0

I have tried multiple reg ex expressions on my ng-pattern in angular js, I have test this pattern on an online regex tester and it works fine

/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][‌​0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) ?[0-9][A-Za-z]{2})$/i

I only want the postcode to contain uppercase characters and the postcode requires a space.

But when I use it inside my app, it allows for lowercase and a space. Which I do not want. Any ideas guys.

user3355603
  • 1,091
  • 2
  • 12
  • 19
  • Are you sure of your requirements? If you need uppercase letters only, why use `[Gg]` instead of `G` and why specify `/i` modifier? There are spaces in your pattern, too. – Wiktor Stribiżew Mar 16 '16 at 10:46
  • http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive – codeninja.sj Mar 16 '16 at 10:54
  • I need uppercase and a space for the post code, ive tried several and i cant seem to get any work – user3355603 Mar 16 '16 at 10:58
  • @user3355603: First reason as Wiktor pointed out, because you are specifying `i`. It's for case insensitive. Even if you allow only ucpper case it will match lower case. And second your reges itself is matching lower case letters. –  Mar 16 '16 at 12:01

0 Answers0