get error in filter name with regex android -


i allow user enter name, allow them use character" z, z, 0 9, comma, space, underscore, dash" only. here code...

pattern pattern_checkname = pattern.compile("^[a-za-z0-9_-,//s//.]{3,}$"); matcher matcher = pattern_checkname.matcher(para); return matcher.matches(); 

and got error, regex syntax error:

06-19 14:27:29.653: e/androidruntime(7735): java.util.regex.patternsyntaxexception: in character range [x-y], x greater 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):     @ java.util.regex.pattern.compileimpl(native method)  06-19 14:27:29.653: e/androidruntime(7735):     @ java.util.regex.pattern.compile(pattern.java:411)  06-19 14:27:29.653: e/androidruntime(7735):     @ java.util.regex.pattern.<init>(pattern.java:394)  06-19 14:27:29.653: e/androidruntime(7735):     @ java.util.regex.pattern.compile(pattern.java:381)  06-19 14:27:29.653: e/androidruntime(7735):     @ com.elite.mm.util.util.checkname(util.java:103)  06-19 14:27:29.653: e/androidruntime(7735):     @ com.elite.mm.activityregister$1.onclick(activityregister.java:89)  06-19 14:27:29.653: e/androidruntime(7735):     @ android.view.view.performclick(view.java:4438)   06-19 14:27:29.653: e/androidruntime(7735):    @ android.view.view$performclick.run(view.java:18422)   06-19 14:27:29.653: e/androidruntime(7735):    @ android.os.handler.handlecallback(handler.java:733)   06-19 14:27:29.653: e/androidruntime(7735):    @ android.os.handler.dispatchmessage(handler.java:95)   06-19 14:27:29.653: e/androidruntime(7735):    @ android.os.looper.loop(looper.java:136)   06-19 14:27:29.653: e/androidruntime(7735):    @ android.app.activitythread.main(activitythread.java:5001)   06-19 14:27:29.653: e/androidruntime(7735):    @ java.lang.reflect.method.invokenative(native method)   06-19 14:27:29.653: e/androidruntime(7735):    @ java.lang.reflect.method.invoke(method.java:515)   06-19 14:27:29.653: e/androidruntime(7735):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785)  06-19 14:27:29.653: e/androidruntime(7735):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601)   06-19 14:27:29.653: e/androidruntime(7735):    @ dalvik.system.nativestart.main(native method) 

any suggestion appreciated. thanks

first of when use - within character class regex engine assume text range if want match literary need put @ end of character class.

also if want match white-space need \s can use following regex :

"^[a-za-z0-9_,\s//.-]{3,}$" 

and more precise instead of a-za-z0-9_ can sue \w match word character, , use space instead of white-space if don't want use dot should remove character class :

"^[\w, /-]{3,}$" 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -