How to write regular expression to match free emai

2019-08-08 19:48发布

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.

3条回答
Juvenile、少年°
2楼-- · 2019-08-08 20:30

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?

查看更多
够拽才男人
3楼-- · 2019-08-08 20:36
/\@(hotmail|yahoo|gmail)\.com/
查看更多
手持菜刀,她持情操
4楼-- · 2019-08-08 20:47

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.

查看更多
登录 后发表回答