Jump to content

how to valid e-mail ?


ms_dos10
 Share

Recommended Posts

Hi i'm new here this my frist topic on the forum & also new to javascript i hope i'll get my help here .how to valid e-mail ? i wanna more info about this object or function becouse it has () indexOf() more explain about it and charAt also . i have this code i want someone to explain it to me and i'll give u link , i'll write some code if i'm going good to vaild that email and also i wanna some help on it .http://www.w3schools.com/js/tryit.asp?file...js_formvalidatemy code here

<script type="text/javascript">//here to check at simplevar email = document.frm.e_mail.valuefor(var i = 0; i <= email.lenght; i++)  if(email.charAt(i) == "@")   {		   alert("enter vaild email ")		   document.frm.e_mail.select()		   return false   }//here to check dot simplefor(var j = 0; j <= email.lenght; j++)  if(email.charAt(j) == ".")   {		   alert("enter vaild email ")		   document.frm.e_mail.select()		   return false   }</script>

i hope i'll get my helpp over here :):):)

Link to comment
Share on other sites

I much prefer a short RegExp validation like:

var theString = 'test@email.com';function testEmail(str){  var reg_email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;  return reg_email.test(str);}var is_valid_email = testEmail(theString);alert(is_valid_email);

Obviously it doesn't test correct domain extensions etc, but it's not a bad starting point. I don't really see the point in smartwebby's multiple indexOf statements, but maybe it's just me. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...