Gossamer Forum
Home : Products : DBMan : Customization :

Email Validation

Quote Reply
Email Validation
Doing an email validation with Javascript..

Keep getting the following errors:

In string, @nw now must be written as \@nw at ./king.pl line 496, near "you need a valid email address - example: joe@nw"
syntax error at ./king.pl line 500, near "} else"


Here is the script:

<SCRIPT LANGUAGE="JavaScript">
function valid(form) {
var field = form.email;
var str = field.value;
if (window.RegExp) {
var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
var reg1 = new RegExp(reg1str);
var reg2 = new RegExp(reg2str);
if (!reg1.test(str) && reg2.test(str))
return true;
alert("you need a valid email address - example: joe@nw-home.com");
field.focus();
field.select();
return false;
} else {
if(str.indexOf("@") >= 0)
return true;

field.focus();
field.select();
return false;
}
}

</script>


<INPUT TYPE="text" NAME="email" SIZE="40" onBlur="return valid(this)>


Any help would be appreciated.

Thanks
Fred
Quote Reply
Re: Email Validation In reply to
I would put all of your Javascript stuff that doesn't need a variable ($rec{'Something'}) within single quotes instead of the qq| | type quote. That should take care of your problem.

So it would be

print '<SCRIPT LANGUAGE="JavaScript">
function valid(form) {
var field = form.email;
etc.
</script>';

However, since DBMan does a really good job of validating, you might just let the script do it instead of adding the Javascript. Up to you, of course.


------------------
JPD





Quote Reply
Re: Email Validation In reply to
Hiya Fred,

The reason you're getting that error is because of the @ sign in the email address, joe@nw-home.com. print qq is dead handy, since you don't have to escape everything, but there are exceptions, @ being one of them.

So if you just change it to joe\@nw-home.com it'll work! (Well, the Perl will but I can't speak for your JavaScript! Smile)

Cheers,
adam

[This message has been edited by dahamsta (edited May 17, 1999).]