[ic] email address as username regexp validation
Dennis Chen
interchange-users@icdevgroup.org
Fri Mar 14 17:28:01 2003
>
> But that regexp needs to match invalid email addresses. I've
> been unable to find a
> regexp online that already does the validation that way;
> usually they test for valid
> email addresses. In the interest of saving time in creating
> a new regexp, I was hoping
> someone on this list already created this regexp and could
> post it here. Alternately, is
> there another way I should be doing this validation? I
> really appreaciate your help
> here.
Some people suggest not to use javascript, but I use this javascript below.
Just add it in your form onsubmit.
<script Language="JavaScript">
function isEmailAddr(email)
{
var result = false
var theStr = new String(email)
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}
function FormValidator(theForm)
{
if (!isEmailAddr(theForm.mv_username.value))
{
alert("Please enter a complete email address in the form:
yourname@yourdomain.com");
theForm.mv_username.focus();
return (false);
}
if (theForm.mv_username.value.length < 3)
{
alert("Please enter at least 3 characters in the \"email\" field.");
theForm.mv_username.focus();
return (false);
}
return (true);
}
</script>