次のコードが正規表現と一致しない理由が本当にわかりません
$val = "12/11/2012";
$opts = {"rule" : "required|format", "format" : {"pattern" : /^\d{1,2}\/\d{1,2}\/\d{4}$/, "errorMsg" : "Invalid date. Allowed allowed: mm/dd/yyyy"}};
if(rule=="format" && typeof $opts.format.pattern==="string") {
try {
var pattern = (typeof $opts.format.pattern==="object") ? $opts.format.pattern : new Regex($opts.format.pattern, "g");
if(pattern.test($val)) { // $val contains 12/11/2012
alert("Invalid Date!"); // Shows invalid format
}
} catch(err){
alert(err.message); // shows pattern.test is not a function
}
}