EmailValidation

Image<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”&gt;
<html>
 <head>
  <title> New Document </title>
  <meta name=”Generator” content=”EditPlus”>
  <meta name=”Author” content=””>
  <meta name=”Keywords” content=””>
  <meta name=”Description” content=””>
 </head>
<script>
function ValidateEmail(inputText)  
{  
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
if(inputText.value.match(mailformat))  
{  
document.form1.text1.focus();  
return true;  
}  
else  
{  
alert(“You have entered an invalid email address!”);  
document.form1.text1.focus();  
return false;  
}  
}
</script>
<body>
<form name=”form1″ action=”#”>   
<input type=’text’ name=’text1’/>
<input type=”submit” name=”submit” value=”Submit” onclick=”ValidateEmail(document.form1.text1)”/></li>  
</form>  
</body>
</html>

 

 

Explanation

/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

Character         Description
/ .. /                  All regular expressions start and end with forward slashes.
^                      Matches the beginning of the string or line.
\w+                  Matches one or more word characters including the underscore. Equivalent to [A-Za-z0-9_].
[\.-]                  \ Indicates that the next character is special and not to be interpreted literally.
.-                      matches character . or -.
?                       Matches the previous character 0 or 1 time. Here previous character is [.-].
\w+                  Matches 1 or more word characters including the underscore. Equivalent to [A-Za-z0-9_].
*                      Matches the previous character 0 or more times.
([.-]?\w+)*        Matches 0 or more occurrences of [.-]?\w+.
\w+([.-]?\w+)*  The sub-expression \w+([.-]?\w+)* is used to match the username in the email. It begins with at least one or more word characters including the underscore, equivalent to [A-Za-z0-9_]. , followed by . or – and . or – must follow by a word character (A-Za-z0-9_).
@                       It matches only @ character.
\w+([.-]?\w+)*     It matches the domain name with the same pattern of user name described above..
\.\w{2,3}             It matches a . followed by two or three word characters, e.g., .edu, .org, .com, .uk, .us, .co etc.
+                        The + sign specifies that the above sub-expression shall occur one or more times, e.g., .com, .co.us, .edu.uk       etc.
$                       Matches the end of the string or line.

 

With Regards

RAJ9992

 

Advertisements
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s