I have been working on a regex for validating an alphanumeric string with the rules as below:
The first FOUR starting characters must be numbers and last TWO characters must be alphabets.
The space is OPTIONAL but must be placed between two characters, meaning trailing space is not allowed.
The length of postal code must be 6 characters if SPACE is not included and 7 characters if space is included.
Eg.
- 1111 ZZ
- 111 1ZZ
- 1 111ZZ
- 1111ZZ
I tried using ^[0-9]{4}[A-Za-z]{2}$|^(?=[\d|\D]+ [\d|\D]+).{7}$ but this also validates 9999 1A as TRUE which should actually be FALSE.
Any leads or help will be appreciated :)