Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  31] [ 3]  / answers: 1 / hits: 27236  / 11 Years ago, mon, april 1, 2013, 12:00:00

I'm making a simple form and having a textbox for street address....
All I want to do is check if the first value entered is a number or not.



How can I do it?



if(document.forms[0].elements[2].value.


that is all I have now but I'm not sure what I should add to it to check the first character only.


More From » forms

 Answers
26

As you said in your question you want to check for the first character only, you can use charAt function for string to check whether the first character is from 0 to 9 or any other check you want for the first character



Possible solution



var firstChar = document.forms[0].elements[2].value.charAt(0);
if( firstChar <='9' && firstChar >='0') {
//do your stuff
}

[#79203] Saturday, March 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amberlykaliac

Total Points: 415
Total Questions: 100
Total Answers: 85

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;