Form Validation With Javascript - Field Value Must Be Between 2 Specific Numbers
I have a form on a page. On the form there is a field named Birthyear. I need to figure out the following in javascript: When a value between 1900-2012 is entered into the field, t
Solution 1:
function validateForm(){
var x=document.forms["myForm"]["username"].value;
if (x==""){
alert("Username Required!");
document.getElementById("username").focus();
}
var dob = document.forms["myForm"]["birthYear"];
var y = dob.value;
if(!isNaN(y)){
if(y>=1900 && y<=2012) {
//Correct
} else {
//Wrong
document.getElementById("birthYear").style.background= "yellow";
document.getElementById("birthYear").focus();
return false;
}
} else {
alert('must be a number');
}
}
Post a Comment for "Form Validation With Javascript - Field Value Must Be Between 2 Specific Numbers"