Regular expression to match "CP" followed by 3-5 digits
8 answers
This will suit your requirements:
^CP\d{3,5}$
The ^ matches the beginning of a line, so it does not allow any characters to the left of "CP".
\ d matches a digit, {3,5} matches 3-5 digits.
$ matches the end of the line, so it doesn't allow characters to be added after numbers.
If you are using regex in a validation control, you can remove the ^ and $ as added by the control:
CP\d{3,5}
+6
a source to share