Skip to content

Commit

Permalink
Merge pull request #634 from betesh/master
Browse files Browse the repository at this point in the history
format validation: without means it's invalid if the match is found
  • Loading branch information
tagliala committed Sep 11, 2015
2 parents 4f43c92 + d0c9773 commit 9e0b844
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coffeescript/rails.validations.coffee
Expand Up @@ -230,7 +230,7 @@ window.ClientSideValidations.validators =
return message

return options.message if options.with and !new RegExp(options.with.source, options.with.options).test(element.val())
return options.message if options.without and !new RegExp(options.without.source, options.without.options).test(element.val())
return options.message if options.without and new RegExp(options.without.source, options.without.options).test(element.val())

numericality: (element, options) ->
val = jQuery.trim(element.val())
Expand Down
12 changes: 12 additions & 0 deletions test/javascript/public/test/validators/format.js
Expand Up @@ -25,3 +25,15 @@ test('when not allowing blank', function() {
var options = { 'message': "failed validation", 'with': /\d+/ };
equal(ClientSideValidations.validators.local.format(element, options), "failed validation");
});

test('when using the without option and the Regex is matched', function() {
var element = $('<input type="text" value="Rock"/>');
var options = { 'message': "failed validation", 'without': /R/ };
equal(ClientSideValidations.validators.local.format(element, options), "failed validation");
});

test('when using the without option and the Regex is not matched', function() {
var element = $('<input type="text" value="Lock"/>');
var options = { 'message': "failed validation", 'without': /R/ };
equal(ClientSideValidations.validators.local.format(element, options), undefined);
});
2 changes: 1 addition & 1 deletion vendor/assets/javascripts/rails.validations.js
Expand Up @@ -320,7 +320,7 @@
if (options["with"] && !new RegExp(options["with"].source, options["with"].options).test(element.val())) {
return options.message;
}
if (options.without && !new RegExp(options.without.source, options.without.options).test(element.val())) {
if (options.without && new RegExp(options.without.source, options.without.options).test(element.val())) {
return options.message;
}
},
Expand Down

0 comments on commit 9e0b844

Please sign in to comment.