how to use javascript to check if the first character in a textbox is a number?

forms, javascript, numbers, textbox

Solution

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
}

Problem

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.

Original source

Related problems