Hi. My form validation page calls an email validation script and that email validation in turn invokes the below javascript to ensure that only valid characters are included in the email address.
However, as we all know, underscores are valid.
The below script apparently is saying that underscores are not valid.
I would have guessed that using the “lowercase” function as this script does, would mean that the underscore should work… but it doesn’t. ALso, I tried including an underscore as one of the regexp characters and that also didn’t work.
Do you know how I could change this so that underscores aren’t found to be invalid (they should at least be valid if they occur prior to the @.. I am not sure about after the @). Thanks.
====
function allValidChars(email) {
var parsed = true;
var validchars = “[email protected]“;
for (var i=0; i < email.length; i++) {
var letter = email.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}