We need to write a RegEx which can validate a CAGE Code
A CAGE Code is a five (5) position code. The format of the code is
- the first and fifth position must be numeric.
- The second, third and fourth may be any mixture of alpha/numeric excluding alpha letters I and O.
We came up with a RegEx cageCode = new RegEx(/^[a-zA-Z0-9]{5}$/)
which is not properly validating the requirements given.
What could be the possible regEx which could validate the requirements mentioned?
2
Answers
You’re trying to match 5 characters which could be either numbers or letters. Try something like this:
To break it down:
A simple regex to achive the requirement is:
This is explained as: