正则表达式以允许在电子邮件地址中尾随空格 [英] Regular expression to allow trailing and leading spaces in email address

查看:79
本文介绍了正则表达式以允许在电子邮件地址中尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在像这样验证电子邮件地址:

I now validate email addresses like so:

[-+.'\w]+@[-.\w]+\.[-.\w]+

这表示如果用户不小心在该地址中包含尾随或前导空格(例如,在复制/粘贴时),该表达式验证为false。

Which means that if users accidentally have a trailing or leading space in that address (e.g. when copy/pasting), the expression validates to false.

所以我想在上面允许尾随和前导空格表达。我该怎么做?

So I want to allow trailing and leading spaces on the above expression. How can I do so?

推荐答案

\s * 上使用正则表达式的结尾和开始。 \s * 表示出现零次或多次的空白。

Use \s* at the end and start of your regex. \s* means white spaces having zero or more occurrence.

这篇关于正则表达式以允许在电子邮件地址中尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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