I have form field where user has to input the number.
Questions:
1) How to check if user inputed a number?
2) Is there any function in javascript to check if string is numeric?
Thank you
Studio64
10-30-2002, 09:39 AM
function CheckPhoneNumber(TheNumber) {
var valid = 1
var GoodChars = "0123456789()-+ "
var i = 0
if (TheNumber=="") {
// Return false if number is empty
valid = 0
}
for (i =0; i <= TheNumber.length -1; i++) {
if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
valid = 0
} // End if statement
} // End for loop
return valid
}
Source (http://webdeveloper.com/javascript/javascript_form_verification_2.html)
First returned item in a Google search for javascript number form verification (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=javascript+number+form+verification)