Hi All,
I'm trying to write a simple javascript form validation script which is
loosely based on the one in the O'Reilly book. I'm calling the verify()
function from the onSubmit handler of the form tag, but I'm having problems
getting it to work. If anyone can spot what I'm doing wrong here I'd be
extremely grateful...TIA, Alan
/*******Validation Script*********/
//returns error statement for bad characters
function checkChar(v) {
var errors = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if ((v.length < 6) || (v.length > 13)) || (illegalChars.test(v)) {
errors = "Valid usernames and passwords consist of 6 to 13 letters or
numbers.";
}
return errors;
}
// returns true if the string contains only whitespace characters
function isBlank(s) {
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ' ) && (c != '\n') && (c != '')) return false;
}
return true;
}
// invoked by the onsubmit event handler
function verify(f) {
var msg;
var empty_fields = "";
for (var i = 0; i < f.elements.length-1; i++) {
var e = f.elements[i];
if ((e.value == null) || (e.value == "") || isblank(e.value)) {
empty_fields += e.name + "\n";
}
}
if (!empty_fields && !errors) return true;
msg = "_______________________________________\n\n"
msg += "Login could not be performed.\n";
msg += "Please correct the following and re-submit.\n";
msg += "_______________________________________\n\n"
if (empty_fields) {
msg += "The following required fields are empty:"
+ empty_fields + "\n";
if (errors) msg += "\n";
}
msg += errors;
alert(msg);
return false;
}
____ � The WDVL Discussion List from WDVL.COM � ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub
________________ http://www.wdvl.com _______________________
You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]