正则表达式空字符串或电子邮件 [英] Regex empty string or email

查看:147
本文介绍了正则表达式空字符串或电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SO中发现了很多Regex电子邮件验证,但是我没有找到任何可以接受的空字符串。这是否可以通过正则表达式?接受空字符串还是电子邮件?

I found a lot of Regex email validation in SO but I did not find any that will accept an empty string. Is this possible through Regex only? Accepting either empty string or email only? I want to have this on Regex only.

推荐答案

这个正则表达式模式将匹配一个空字符串:

This regex pattern will match an empty string:

^$

将(粗略地)匹配(粗略地)电子邮件或空字符串:

And this will match (crudely) an email or an empty string:

(^$|^.*@.*\..*$)

这篇关于正则表达式空字符串或电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆