Click to See Complete Forum and Search --> : Form Validation


critters
04-04-2003, 10:54 AM
I have a form validation script that works fine for most of my form, but I have a need for special validation for a drop down field, the e-mail field, and password field. I found a validation script that does the drop-down, another one that does the e-mail, and still another one that does the password. Can I combine them all, or if not, can I have more than one script validating the same form?

Most of the fields I just need to check for null, but the e-mail needs verification that it’s an e-mail address (check for @ and .), and a password field that needs to be entered twice and verified that they are the same both times.

Is it stupid to try to combine scripts I’ve found, or should I keep looking for one that fits my needs? I’m not a very good JavaScript programmer, but I can tweak scripts to fit what I want … that is until now!

Please help,

Critters

Nedals
04-04-2003, 01:10 PM
function validate() {
// form fields, elements, number 0 to n, so run a loop that tests each field.
theform = document.formname;
for (i=0; i<theform.elements.length; i++) {
if (i == email element no) { do an email check )
else if (i == password element no) { compare this, elements[i] and the next, elements[i+1]; i++ }
else { check elements[i] for null }
}
}

Hope this makes sense to you! :)

critters
04-04-2003, 01:24 PM
Oh, yes - it does make sense. Thanks!!