admin管理员组文章数量:1386523
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
3 Answers
Reset to default 3function 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
本文标签: aspnetJavaScript Email validationStack Overflow
版权声明:本文标题:asp.net - JavaScript Email validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744508545a2609735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论