问题描述
今天,我们经历了奇怪的行为模式。
例如,在3.2股市ROM平板电脑(previously 4.0 +),效果很好。
但在其他一些平板电脑3.2和4.0的设备没有。
功能来测试电子邮件功能是这样的:
公共静态布尔checkEmail(CharSequence的EMAILADDRESS){
如果(Build.VERSION.SDK_INT> = 8){
返回android.util.Patterns.EMAIL_ADDRESS.matcher(EMAILADDRESS).matches();
}
....
原来这就是我在电子邮件16'th源ADDRES模式(JAVA code):
公共静态最终模式EMAIL_ADDRESS
= Pattern.compile(
[A-ZA-Z0-9 \\\\ + \\\\ _ \\\\ \\\\% - \\\\ +] {} 1,256+
\\\\ @+
[A-ZA-Z0-9] [A-ZA-Z0-9 \\\\ - ] {0,64}+
(+
\\\\。 +
[A-ZA-Z0-9] [A-ZA-Z0-9 \\\\ - ] {0,25}+
)+
);
下面是规范化的版本:
<$p$p><$c$c>[a-zA-Z0-9\\\\+\\\\.\\\\_\\\\%\\\\-\\\\+]{1,256}\\\\@[a-zA-Z0-9][a-zA-Z0-9\\\\-]{0,64}(\\\\.[a-zA-Z0-9][a-zA-Z0-9\\\\-]{0,25})+ ( JS 正则表达式验证)告诉这个正则表达式主要是正确的,但在一轮梅开二度的 \\\\。
应 \\
和 \\\\ @
应 \\ @
在regexpal工作。
此外,它是不是很清楚,为什么有两个\\ +符号组第一支撑?
我们目前的解决方案,它的工作:
<$p$p><$c$c>[a-zA-Z0-9\\\\+\\\\.\\\\_\\\\%\\\\-\\\\+]{1,256}[\\\\@]{1}[a-zA-Z0-9][a-zA-Z0-9\\\\-]{0,64}([\\\\.]{1}[a-zA-Z0-9][a-zA-Z0-9\\\\-]{0,25})+Today we experienced strange pattern behaviour.
For instance, on tablet with 3.2 stock rom(previously 4.0.+) it works well.
But on some other 3.2 tablets and 4.0 devices it doesn't.
Function to test email functionality is like:
public static boolean checkEmail(CharSequence emailAddress){
if( Build.VERSION.SDK_INT >= 8 ){
return android.util.Patterns.EMAIL_ADDRESS.matcher(emailAddress).matches();
}
....
So this is what I have in 16'th sources for email addres pattern(JAVA code):
public static final Pattern EMAIL_ADDRESS
= Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+"
);
Here is 'normalised' version:
[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}\\@[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}(\\.[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25})+
Regexpal(JS regex validator) tells that this regexp is mostly proper, but in round brace the \\.
should be \.
and \\@
should be \@
to work in regexpal.
Moreover it is not quite clear, why there are two '\+' group of symbols in first braces?
Our current solution, which worked:
[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}[\\@]{1}[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}([\\.]{1}[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25})+
这篇关于Android的android.util.Patterns.EMAIL_ADDRESS奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!