I'd like to validate an email address via javascript using a regular expression. The expression is something I pinched from a search and it doesn't seem to work.
Could anyone give me an idea as to why I'm going wrong?
Code: Select all
<html>
<head>
<script>
function fncTestRegex()
{
MyRegex="/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i";
MyString="matt@waferthinmint.com";
alert("Regex="+MyRegex+"\rTest="+MyString);
if(!MyString.match(MyRegex)){alert('Pattern returned with a false')}
}
</script>
</head>
<body>
<input type="button" value="go for it" onclick="fncTestRegex()">
</body>
</html>Matt