function validate() {
var forename = document.getElementById('forename').value;
var alpha = /^[a-zA-Z\s]+$/;
var num = /^[0-9]+$/;
var space = " ";
if (forename == "") {
alert("Please fill out the First Name field.");
return false;
}
if (forename.indexOf(" ") > -1) {
alert("No spaces are allowed in the First Name field.");
return false;
}
if (forename.value.match(num)) {
alert("No numbers are allowed in the First Name field.");
return false;
}
The above code is part of a validation function for a registration form.
For whatever reason I cannot get my all letters/all numbers if statements to work. Without them the form processes perfectly, however when I start including any value.match argument it breaks the function from that point on. Am I missing anything obvious here?