是否有HTML5输入电子邮件验证的Java实现? [英] Is there a Java implementation of the HTML5 input email validation?
本文介绍了是否有HTML5输入电子邮件验证的Java实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用新的< input type =email/>
元素。我希望Java代码在浏览器中实现的服务器上实现相同的验证。
I'd like to use the new <input type="email" />
element. I'd like to have Java code that implements the same validation on the server that happens in the browser.
HTML5规范定义了中的电子邮件地址 ABNF as:
The HTML5 spec defines email addresses in ABNF as:
1*( atext / "." ) "@" ldh-str *( "." ldh-str )
其中:
<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
<let-dig-hyp> ::= <let-dig> | "-"
<let-dig> ::= <letter> | <digit>
<letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
<digit> ::= any one of the ten digits 0 through 9
和:
atext = ALPHA / DIGIT / ; Printable US-ASCII
"!" / "#" / ; characters not including
"$" / "%" / ; specials. Used for atoms.
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
这些不与 RFC 5322 中的规则相同。
如何在Java中测试地址是否符合这些规则?
These are not the same rules as in RFC 5322. How can I test that an address complies with these rules in Java?
谢谢!
推荐答案
你可以使用正则表达式:
You can use a regex:
[A-Za-z0-9!#$%&'*+-/=?^_`{|}~]+@[A-Za-z0-9-]+(.[A-Za-z0-9-]+)*
这篇关于是否有HTML5输入电子邮件验证的Java实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文