Forum Moderators: open
<input type="text" onBlur="isValid(this);">
</body>
<script language="javascript">
function isValid(object) {
var email = /\w{1,}[@]\w{1,}([.](\w{1,})){1,2}$/;
if (!email.test(object.value)) {
alert("The email address you entered, "+object.value+", is not valid by our sensors.");
}
}
</script>
var emailRegExp = /^[a-z0-9_.-]*[a-z0-9]+@[a-z0-9_.-]*[a-z0-9]+\.([a-z]{2,4}¦[a-z]{6})$/i ; function checkEmail (email)
{ var returneres = "" ;
if ( email.match(emailRegExp) == null ) returneres = "<li>email-adressen er ikke korrekt</li>" ;
return returneres} this is a more strict test than the one posted by adni18.
1) there has to be at least one letter/digit before _.- is allowed.
2) it takes into account ccTLD (2 letters) old-gTLD (3 letters) new-gTLD (3, 4 & 6 letters)
it't by no means perfect. writing regExps that checks for correctness in an email address is no simple matter and *very* prone to errors. I don't think that mine is correct and can be fooled, but it'll catch the most obvious errors.
this doesn't take into account one form, that I've never seen in real life: name@[123.123.123.123]
/^[a-z0-9]([a-z0-9]¦([\w\-]+[a-z0-9]))*(\.([a-z0-9]¦[a-z0-9][\w\-]+[a-z0-9]))*@[a-z0-9][\w\-]*[a-z0-9]\.([a-z0-9][\w\-]*[a-z0-9]\.)*[a-z]{2,6}$/i;
There has to be at least one letter/digit before _.- is allowed. ;)
Keep in mind that RFC822 is pretty liberal about valid addresses. Addresses with % are also allowed. A well-known pattern that supposedly covers everything is the pattern halfway down this page [search.cpan.org] . It's written in Perl, but AFAIK the regex-syntax JavaScript uses is quite similar to Perl's.