0
  • i have an edit text, in which the name is entered. When i click the
    button it should do a check.

  • the check should be like, the word contains any characters $ [ ] . # +

when i used regex

Pattern regex = Pattern.compile("[$. #+]");
 else if(regex.matcher(name).find()) {
                showDialog(this, "invalid");
            }

i was not able to give [] check is their any other way to check the existence of $ [ ] . # + characters.

Yadu Mohan
  • 39
  • 3
  • then it shows illegal escape character in Pattern.compile("[$. #+]"); @Ken Y-N – Yadu Mohan Apr 19 '18 at 08:44
  • Oops, I meant double-escape `"\\[\\$\\. #\\+\\]"` - I think that's right... – Ken Y-N Apr 19 '18 at 08:45
  • Possible duplicate of [List of all special characters that need to be escaped in a regex](https://stackoverflow.com/questions/14134558/list-of-all-special-characters-that-need-to-be-escaped-in-a-regex) – Ken Y-N Apr 19 '18 at 08:48

0 Answers0