regular expression if-then
I'm trying to use a regular expression to validate a multi-line entry of 4 letters followed by 6 numbers. Following that requirement, the user may enter a comma followed by a number, or hit <Enter> to enter a second required value:
abcd000001
abcd000002,1
abcd000003,16
The comma is optional, but if present must be followed by a number.
For the "if comma then match number" I tried this, but I get a syntax error.
var re = new RegExp(/[A-Za-z]{4}\d{6}\,?(?(1)\d+)/);
Everything through the comma works:
var re = new RegExp(/[A-Za-z]{4}\d{6}\,?/);
but the if-then part causes the error.
|