I am having a text box . I have to restrict user from entering multiple space in the beginning of the text box.
eg:
1.abc d e (Should allow)
2.$$$abc(Should not allow.Here $ I have put to represent space character)
And also should also validate if the user is entering space character only(multiple times also)
Please help me how to resolve this using jquery.
Loading
Sunny SharmaPosted Jun 18, 2014, 6:34 AM
$(document).ready(function(){
$('#name').on('keydown',function(e){
$('.msg').text('');
var $name = $(this).val();
if(e.keyCode==32 & $name[$name.length-1]==' ')
{
$('.msg').text('Multiple spaces not allowed!');
return false;
}
});
})
Replace the IDs of textbox and div to per yours and you're good to go.
Refer to this sample fiddle if you need a demo:
http://jsfiddle.net/sunnykumar08/Cx6DH/
Happy Learning :)
Amit ThoratPosted Jun 18, 2014, 6:01 AM
please refer to the link
http://stackoverflow.com/questions/2809311/how-to-prevent-user-to-enter-space-at-the-
beginning-in-textbox