« Previous entry | Next entry » Browse > Snippets

Skip to comments (4) Javascript email check example.
Posted by Assaf on Nov 18 2007 @ 13:17  :: 1059 unique visits

<html dir="ltr">
<head>
  <title> Email Checking </title>
 <script language="JavaScript">
   function CheckVaild(FormName) {
   var length = document[FormName].email.value.length;
   var counter = 0;
var MSG = "";
for(i=0;i<length;i++) {
if( (document[FormName].email.value.charAt(i) < 'a' || document[FormName].email.value.charAt(i) > 'z') &&
   (document[FormName].email.value.charAt(i) < 'A' || document[FormName].email.value.charAt(i) > 'Z') ) {
if(document[FormName].email.value.charAt(i) != '@') {
if(MSG.length == 0)
MSG = MSG + "Email is not in english\n";
}
else
if(i > 0 && i < length-1)
counter++;
}
}
if( document[FormName].email.value.length < 2)
MSG = MSG + "Email is too short\n" ;
if(counter != 1)
MSG = MSG + "Email is not vaild\n";

if(MSG.length>0)
alert(MSG);
else
alert("Email is vaild");
  }
  </script>
 
</head>

<body>
<h2> Email Check </h3>
<br/> <br />

<form name="E-FORM">
Email:
<input type="text" name="email" size="20" />
&nbsp&nbsp
<input type="button" value="Check" onclick="CheckVaild('E-FORM')" />
</form>
</body>


</html>

4 comments posted so far
Add your own »

1. On Dec 27 2007 @ 14:54 guest wrote:

Why not using regular expression? Would be easier, shorter and more obviously what the code actually does.
Moreover "foo@bar.com" does not evaluate to a valid email address with your code.

2. On May 13 2009 @ 15:53 guest wrote:

Need Furniture? And need to buy furniture from China at competitive price? LongYear Furniture is your source for quality bedroom furniture featuring a huge selection of home furniture a happy home for beautiful life, kids furniture for a good memory of childhood, and to gain an extra good price from wholesale furniture and direct from  furniture manufacturers China, styles of China furniture are available, living room furniture is also nice for your house, find dining room furniture and more!

4. On Jan 05 2010 @ 14:57 uggbaileybutton wrote:

bailey button uggs

-ugg boots cheap

ugg boots uk

ugg classic

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: