I have this regular expression to help me validate a form input.
var nrExp = /^\d{6}\-\d{4}$/;
This allows only 10 digits, where the last 4 digits are separated with a “minus sign”.
012345-6789
I need to make it also allow it without the minus-sign AND with a space instead of a minus-sign:
0123456789
012345 6789
How can I remake this regexp to allow what I want?
Thanks
Sure. You just want to make the minus optional, along with a couple of other characters.
Try this one:
Notice the
?after the(\-| ). This allows that match portion to be optional.