0

I have two regexes

1.) For invalidating PO Box:

^(?!.*\b[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]\b).*$

2.) For invalidating special characters:

[^x21-x7E][^x20-x7E]*$

How can I combine these two that it invalidates PO Box in address form as well as disallow special characters? I tried different things with no luck. I also tried @Pattern.List and added both regex but it doesn't work. @Pattern.List() always invalidates all my inputs. Any help will be highly appreciated.

Dean Taylor
  • 40,514
  • 3
  • 31
  • 50

1 Answers1

0

Here is a simple example of using more regex in one pattern. But in your code, i think there is a problem because of your both regex ends with "$".

String regex1="(\\d)";  // Any Single Digit 1
String regex2="(\\d)";  // Any Single Digit 2

Pattern p = Pattern.compile(re1+re2,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(txt);
if (m.find())
{
   //jobs ...
}
reigeki
  • 391
  • 1
  • 5
  • 19