Quote:
Originally Posted by gjcluttrell
If there anyway to edit the last name field java code so if the user last a trailing space or a - or a . it will throw a message
|
Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!
Form validation of the pattern if(document.forms[0].lname.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation.
A proper name may only contain letters, hyphen, space and apostrophe.
Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses.
This topic has been covered many times before in this forum.
Forms names are obsolete - use an id rather than a name. Likewise docuemnt.forms[0] is considered undesirable.
To permit only letters, hyphens, apostrophes in a field:
Code:
var lstn = document.forms[0].lname.value;
lstn = lstn.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces
lstn = lstn.toLowerCase().replace(/\d[a-z]/g,function(w){return w.toUpperCase()}); // capitalise first letter of each word, other letters lower-case
document.forms[0].lname.value = lstn; // write it back to the field
if (/[^a-z\-\'\s]/gi.test(lstn)) { // test for invalid characters
alert ("Only letters, hyphens and apostrophe (and intermediate space) allowed in this field"); // remove \s if spaces not allowed
document.forms[0].lname.value = ""; // clear the field
document.forms[0].lname.focus(); // and refocus on it
return false;
}
All your other fields should be properly validated in a similar way.
See anything wrong here?
Code:
if(document.forms[0].location.value == "") {
alert("ATTENTION: Please choose a location.");
document.forms[0].fname.focus();
return(false)
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.