Click here to Skip to main content
14,982,215 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to check whether email id is valid?
Posted

You can use validation control....

REGULAR Expression control help to you.
   
JavaScript
\\javascript code
function validate(form_id,email) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {

      alert('Invalid Email Address');
      return false;
   }
}


In the forms ‘onsubmit’ code call javascript:return validate(‘form_id’,'email_field_id’)

XML
<form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');">

   <input type="text" id="email" name="email" />

   <input type="submit" value="Submit" />
</form
   
v3
function validate(form_id,email) {

var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {

alert('Invalid Email Address');
return false;
}
}
<form id="form_id" method="post" action="action.php" önsubmit="javascript:return validate('form_id','email');">

<input type="text" id="email" name="email" />

<input type="submit" value="Submit" />
</form>
   
Use regular expression validator
C#
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>

tbEmail is textBox that need to validate.

See
http://regexlib.com/DisplayPatterns.aspx[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900