I'm currently using this RegEx ^(0[1-9]|1[0-2])/(19|2[0-1])\d{2}$ in .NET to validate a field with Month and Year (12/2000).
I'm changing all my RegEx validations to JavaScript and I'm facing an issue with this one because of /in the middle which I'm having problems escaping.
So based on other answers in SO I tried:
RegExp.quote = function (str) {
return (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&");
};
var reDOB = '^(0[1-9]|1[0-2])/(19|2[0-1])\d{2}$'
var re = new RegExp(RegExp.quote(reDOB));
if (!re.test(args.Value)) {
args.IsValid = false;
return;
}
However, validations fails even with valid data.
var re = /^(0[1-9]|1[0-2])\/(19|2[0-1])\d{2}$/;which uses the regex operator//??rethere as a regex object ?var re = /.../;regex object, as opposed tovar s = '...';bstr object./^([1-9]|1[0-2])\/(19|2[0-1])\d{2}$/