I am trying to understand regular expressions and javascript. I wanted to try and validate an email address.
I read a tutorial on using reqular expressions and they had a sample validating an SSN
Link
I took that example and incorporated an expression for an email address I got from here.
I could not get it to work and I have supplied my sample below. I appreciate any help. Thanks Howard
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "<html>
<head>
<title>ssn Checker</title>
<script type="text/javascript">
var RE_EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/;
function checkEmail(email){
if (RE_EMAIL.test(email)) {
alert("VALID EMAIL");
} else {
alert("INVALID EMAIL");
}
}
</script>
</head>
<body>
<form onsubmit="return false;">
<input type="text" name="email" size="20">
<input type="button" value="Check"
onclick="checkEmail(this.form.email.value);">
</form>
</body>
</html>
I read a tutorial on using reqular expressions and they had a sample validating an SSN
Link
I took that example and incorporated an expression for an email address I got from here.
I could not get it to work and I have supplied my sample below. I appreciate any help. Thanks Howard
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "<html>
<head>
<title>ssn Checker</title>
<script type="text/javascript">
var RE_EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/;
function checkEmail(email){
if (RE_EMAIL.test(email)) {
alert("VALID EMAIL");
} else {
alert("INVALID EMAIL");
}
}
</script>
</head>
<body>
<form onsubmit="return false;">
<input type="text" name="email" size="20">
<input type="button" value="Check"
onclick="checkEmail(this.form.email.value);">
</form>
</body>
</html>