mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-14 20:35:47 +01:00
Additionals: Fix pattern method when parameter is a string
Reverts 37992c1c9e
The pattern should match the entire value of the input, not just a subset.
Closes #1204
This commit is contained in:
committed by
Jörn Zaefferer
parent
9f4ba10ea7
commit
4cecd73649
@@ -16,7 +16,7 @@ $.validator.addMethod("pattern", function(value, element, param) {
|
||||
return true;
|
||||
}
|
||||
if (typeof param === "string") {
|
||||
param = new RegExp(param);
|
||||
param = new RegExp("^(?:" + param + ")$");
|
||||
}
|
||||
return param.test(value);
|
||||
}, "Invalid format.");
|
||||
|
||||
@@ -918,6 +918,13 @@ test("pattern", function() {
|
||||
ok( method( "AR1004", "AR\\d{4}" ), "Correct format for the given RegExp" );
|
||||
ok( method( "AR1004", /^AR\d{4}$/ ), "Correct format for the given RegExp" );
|
||||
ok(!method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" );
|
||||
ok( method( "1ABC", "[0-9][A-Z]{3}" ), "Correct format for the given RegExp" );
|
||||
ok(!method( "ABC", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );
|
||||
ok(!method( "1ABC DEF", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );
|
||||
ok( method( "1ABCdef", "[a-zA-Z0-9]+" ), "Correct format for the given RegExp" );
|
||||
ok(!method( "1ABC def", "[a-zA-Z0-9]+" ), "Invalid format for the given RegExp" );
|
||||
ok( method( "2014-10-02", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Correct format for the given RegExp" );
|
||||
ok(!method( "02-10-2014", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Invalid format for the given RegExp" );
|
||||
});
|
||||
|
||||
function testCardTypeByNumber(number, cardname, expected) {
|
||||
|
||||
Reference in New Issue
Block a user