How to write regular expression to match free email accounts?

此生再无相见时 提交于 2020-01-06 02:22:30

问题


I'm trying to write a regular expression that checks if an email form field contains a free email address, with no luck.

Essentially I need to check if the email contains: hotmail, yahoo, gmail etc in the email field.


回答1:


regex would be sth like:

[a-zA-Z0-9_\.+]+@(gmail|yahoo|hotmail)(\.[a-z]{2,3}){1,2}

you can add all the other domains you want... does it help you?




回答2:


/\@(hotmail|yahoo|gmail)\.com/



回答3:


Have you tried a big ol' disjunction?

i.e.

yahoo\.com|googlemail\.com|blah\.net

Pros: Easy to build, easy to read, explicit.

Cons: Maybe not the most efficient mechanism.



来源:https://stackoverflow.com/questions/2318214/how-to-write-regular-expression-to-match-free-email-accounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!