包括电子邮件地址验证,以便电子邮件具有@ gmail.com扩展名 [英] Include validation for email address so that the email has @gmail.com extension
问题描述
任何人都可以帮我完成这项任务。我有一个接受电子邮件地址的文本框。我们需要验证电子邮件地址,使其只有@ gmail.com扩展名。如果电子邮件地址无效,我需要使用红色背景制作div,并显示电子邮件无效的错误消息。
Can anyone help me to do this task. I have got a textbox that accept the email address. We need to validate the email address such that it has only "@gmail.com " extension. If the email address is not valid I need to make the div with red background and also display an error message that the email is not valid.
<div class="detailsRow" id="VAREmail">
<div class="detailsLabel">
@Html.LabelFor(m => m.VAREmail, Strings.VAREmail)
</div>
@Html.TextBoxFor(m => m.VAREmail, new { style = "width:50%" })
@Html.ValidationMessageFor(m => m.VAREmail)
</div>
我尝试了什么:
我尝试使用javascript但是我不能使它成为
var email = document.getElementById(VAREmail)。next()。value;
var filter = ^(? i)[A-Z0-9 ._%+ - ] + @(gmail.com);
if(!filter.test(email))
{
document.getElementById(VAREmail)。style.backgroundColor =maroon;
}
What I have tried:
I tried using a javascript but I couldn't make it
var email = document.getElementById("VAREmail").next().value;
var filter = ^(?i)[A-Z0-9._%+-]+@(gmail.com);
if(!filter.test(email))
{
document.getElementById("VAREmail").style.backgroundColor = "maroon";
}
推荐答案
试试正则表达式:
Try a regex:
^[\w!#
%&'* + - / =?^ _ `{|}〜] {1,64} @ gmail.com
%&'*+-/=?^_`{|}~]{1,64}@gmail.com
应该这样做。
这篇关于包括电子邮件地址验证,以便电子邮件具有@ gmail.com扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!