Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to set validation via javascript for spacing in front of a string typed in the textbox.
Posted
Comments
JoCodes 5-Nov-13 2:40am    
Only front space ? space between words should be validated?

 
Share this answer
 
If your intention is to validate only the leading space try the indexOf method in Javascript

Something like below

C#
function CheckLeadingSpace()
{
  var txt= document.getElementById('txtBoxID');
  var n=txt.value.indexOf(" ",0);//Checks the space in position 1
  if (n == 0) {
            alert("InValid");
            return false;
   }
  return true;

}

Try this on TextBox onblur or keyup event etc. 

Hope this helps...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900