验证Java中包含非英语(UTF-8)字符的电子邮件地址
我有以下电子邮件 ID,
闪闪发光@闪闪发光.com
我需要在服务器端验证此类电子邮件,以便用户无法输入此类电子邮件..
我已经通过使用下面的正则表达式解决了 javascript 中的类似问题 -
/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/gi
但是。无法在java中做同样的事情。请帮助我。
提前致谢!!!
i am having fallowing email id
闪闪发光@闪闪发光.com
i need to validate this type of email at server side so that user can not enter this type of email..
i have solved similar problem in javascript by using below regex-
/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/gi
But. unable to do same thing in java.Please help me guys.
Thanks in advance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 正则表达式模式
(?i)[-a-z0-9+_][-a-z0-9+_.]*@[-a-z0-9][-a-z0-9 .]*\\.[az]{2,6}
应该足够了。该模式的含义如下:以下测试代码......
将输出:
通过使用
Matcher.matches()
方法,您不需要包含^ 行首或
$
行尾边界匹配构造,因为Matcher.matches()
将匹配整个字符串。The Java regular expression pattern
(?i)[-a-z0-9+_][-a-z0-9+_.]*@[-a-z0-9][-a-z0-9.]*\\.[a-z]{2,6}
should suffice. Here's what the pattern means:The following test code ...
... will output:
By using the
Matcher.matches()
method, you don't need to include the^
start-of-line or$
end-of-line boundary matching constructs sinceMatcher.matches()
will match on the whole string.[更新] 抱歉js代码。试试这个:
[Update] Sorry for the js code. Try this: