How can I disable space as first character in the textbox in asp.net c# using jquery?
3 Answers
You can achieve this using JQUERY as below:
$(function(){
$("#a").keypress(function(evt){
var cc = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if($(this).val().length==0){
if(cc==32)
return false;
}
});
});
a is the your textbox Id
Comments
This problem isn't related to C#/asp.net. All u need is javascript.
just try to catch the onkeydown event.
$("#text").keydown(function(){
var txt = $(this).value;
if(txt.charAt(0)==' '){
alert("No space in the beginning");
txt.value(txt.replace(" ",""));//clear first space in text
}
});
text is id of input