最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - JavaScript Email validation - Stack Overflow

programmeradmin0浏览0评论

I want to apply javascript email validation in my project so please some suggest me the exact code for that because i just want to apply it only for regular expression and i don't want to add any plug in for it. is it possible to write some code in source file and apply to email field.

Thanks in advance

I want to apply javascript email validation in my project so please some suggest me the exact code for that because i just want to apply it only for regular expression and i don't want to add any plug in for it. is it possible to write some code in source file and apply to email field.

Thanks in advance

Share Improve this question asked Aug 5, 2011 at 5:28 Ram SinghRam Singh 6,93835 gold badges107 silver badges170 bronze badges 1
  • possible duplicate of Validate email address in Javascript? – Callie J Commented Apr 3, 2012 at 16:52
Add a ment  | 

3 Answers 3

Reset to default 3
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)) {     
      alert('Invalid Email Address');
      return false;
   }
}

you can add a regular expression validator to validate you email.

<asp:TextBox ID="txtEmailAddress" runat="server" ></asp:TextBox>
                        <asp:RegularExpressionValidator ID="valRegExEmail" runat="server" ControlToValidate="txtEmailAddress"
                            Display="None" ErrorMessage="Please give a valid email address" ValidationGroup="StaffAddValidation" ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z\.][a-zA-Z]{1,3}$"></asp:RegularExpressionValidator> 

or if you want to check email from from javascript . check the SO post

You can use regular expression (/^([\w.-]+)@([\w-]+)((.(\w){2,3})+)$/i) to validate email address. var emailRegex = new RegExp(/^([\w.-]+)@([\w-]+)((.(\w){2,3})+)$/i);

var valid = emailRegex.test(emailAddress);
if (!valid) {
alert("Invalid e-mail address");
return false;
} 
else
 return true;

Get example code here: http://www.codegateway./2012/03/regex-for-email-validation-javascript.html Also see example how to validate email address using RegularExpressionValidator http://www.codegateway./2012/03/validate-email-format.html

发布评论

评论列表(0)

  1. 暂无评论