简体   繁体   English

javascript正则表达式来测试电子邮件

[英]javascript regular expression to test e-mail

I am trying to check the e-amil address like abc@example.co.uk or a.bc@eyample.com etc 我正在尝试检查abc@example.co.uk或a.bc@eyample.com等e-amil地址

and I am using regular expression like 我正在使用正则表达式

[a-zA-Z0-9\._]+@[^.]+[a.zA-Z]+\.[a-z{2,5}]+

Can someone suggest how to correct it? 有人可以建议如何纠正它吗?

Thank you 谢谢

See Using a regular expression to validate an email address 请参阅使用正则表达式来验证电子邮件地址

and you can try : 你可以尝试:

[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*

This should work 这应该工作

Example

var sEmail = txtEmail;

var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

if (filter.test(sEmail)) {
    return true;
}
else {
    return false;
}

If you make an input type email in new browsers it will validate to a certain level. 如果您在新的浏览器中输入电子邮件类型,它将在一定程度上进行验证。 It will only look for characters followed by a @ and than a few characters after it. 它只会查找后面跟有@的字符,之后是几个字符。

Validating is to catch user mistakes not to make it harder for users to fill in your form. 验证是为了捕获用户错误,而不是使用户难以填写您的表单。

I want to replace apostrophes "'" with "/" from string. 我想用字符串中的“ /”替换撇号“'”。

for example: var str ="te'xt"; 例如:var str =“ te'xt”; want output like this "te/xt" 想要这样的输出“ te / xt”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM