2017-02-17 80 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?)+$"