2017-02-17 81 views
1

你好不起作用怎么办正则表达式我要为AZ AZ0_9آ-ی(波斯)正则表达式android系统

String regex ="^(?:([a-z A-Z 0-9])||([آ-ی]))+$"; 

我不想让特殊字符,如!@#$%^ & *() ?> < + - 。

和我commllet代码是:如果你想允许正则表达式的空间变化结束

public int check_first_last_name(String name){ 
    String regex ="^(?:([a-zA-Z0-9])||([آ-ی]))+$"; 
Matcher matcher = Pattern.compile(regex).matcher(name); 
if (!matcher.find()){ 
    return 2; 
} 
return 1; 
} 
+1

'^(?:([A-ZA-Z0-9])|([آ-ی]) )+ $',''||应该是'|'和清晰度添加您的有效病例和无效的病例,并说明究竟你想 –

+0

我修改的内容和修复我的错误。看看它 –

回答

1

这个表达式接受英语,波斯语和阿拉伯语的每一个字“...... 0-9”

if(name.matches("^([\\u0600-\\u06FF\\uFB8A\\u067E\\u0686\\u06AFa-zA-Z0-9])+$")){ 
//do what you want 
} 

请检查代码,您必须有2个反斜杠每个unicode不前4!

,如果你想接受所有选项卡换行和空间,你可以使用这个表达式:

"^([\\u0600-\\u06FF\\uFB8A\\u067E\\u0686\\u06AFa-zA-Z0-9]+\\s?)+$"