1
我會允許用戶輸入名稱,只允許他們使用「a到z,A到Z,0到9,逗號,空格,下劃線,短劃線」這個字符。這裏是我的代碼...在正則表達式中得到錯誤filter
Pattern pattern_checkName = Pattern.compile("^[a-zA-Z0-9_-,//s//.]{3,}$");
Matcher matcher = pattern_checkName.matcher(para);
return matcher.matches();
而且我得到了這個錯誤,正則表達式語法錯誤:
06-19 14:27:29.653: E/AndroidRuntime(7735): java.util.regex.PatternSyntaxException: In a character range [x-y], x is greater than y near index
14:06-19 14:27:29.653: E/AndroidRuntime(7735): ^[a-zA-Z0-9_-,//s//.]{3,}$
06-19 14:27:29.653: E/AndroidRuntime(7735):
^
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.util.regex.Pattern.compileImpl(Native Method)
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.util.regex.Pattern.compile(Pattern.java:411)
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.util.regex.Pattern.<init>(Pattern.java:394)
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.util.regex.Pattern.compile(Pattern.java:381)
06-19 14:27:29.653: E/AndroidRuntime(7735): at com.elite.mm.util.Util.checkName(Util.java:103)
06-19 14:27:29.653: E/AndroidRuntime(7735): at com.elite.mm.ActivityRegister$1.onClick(ActivityRegister.java:89)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.view.View.performClick(View.java:4438)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.view.View$PerformClick.run(View.java:18422)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.os.Handler.handleCallback(Handler.java:733)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.os.Handler.dispatchMessage(Handler.java:95)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.os.Looper.loop(Looper.java:136)
06-19 14:27:29.653: E/AndroidRuntime(7735): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 14:27:29.653: E/AndroidRuntime(7735): at java.lang.reflect.Method.invoke(Method.java:515)
06-19 14:27:29.653: E/AndroidRuntime(7735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-19 14:27:29.653: E/AndroidRuntime(7735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-19 14:27:29.653: E/AndroidRuntime(7735): at dalvik.system.NativeStart.main(Native Method)
任何建議是極大的讚賞。 感謝
非常有幫助,感謝解決這個問題。 – NSA
@NSA歡迎;) – Kasramvd