Friday, 15 August 2014

Need help in regex pattern which excludes special character in android -



Need help in regex pattern which excludes special character in android -

i want regular look restrict user accepting special character in android.

i have tried this:

!phonenumber.matches("[/,'*:<>!~@#$%^&()+=?()\"|!\[#$-]")

but homecoming true regardless of whether phone number contains special character or not.

your regex [/,'*:<>!~@#$%^&()+=?()\"|!\[#$-] matches of listed character occuring 1 time , negation. !phonenumber.matches("[/,'*:<>!~@#$%^&()+=?()\"|!\[#$-]") evaluates true whether a or aa or a! aa , a! not one of characters specified. case evaluating false a single occurrence of of these characters.

you have take characters other these. should utilize ^ next character class opening bracket ([) , add together + next closing bracket. regex matches 1 or more characters other listed ones.

required regex "[^/,'*:<>!~@#$%^&()+=?()\"|!\\[#$-]+" matches patterns 1 or more characters other these.

note: implementation seems in java. regex works in java.

another thing : why have added \" instead of "? if escape " within string, can't give \[ requires \\[ think.

regex

No comments:

Post a Comment