validate.js
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -5,3 +5,3 @@ { | ||
"main": "validate.js", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"moduleType": [ | ||
@@ -8,0 +8,0 @@ "amd", |
@@ -8,5 +8,5 @@ { | ||
"scripts" : ["validate.js"], | ||
"version" : "0.10.0", | ||
"version" : "0.11.0", | ||
"license" : "MIT" | ||
} | ||
{ | ||
"name": "validate.js", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"author": "Nicklas Ansman <nicklas@ansman.se>", | ||
"description": "Declarative validations for JavaScript", | ||
"main": "validate.js", | ||
"typings": "validate.d.ts", | ||
"homepage": "http://validatejs.org", | ||
@@ -25,13 +26,13 @@ "repository": { | ||
"devDependencies": { | ||
"grunt": "0.4.5", | ||
"grunt-notify": "0.4.1", | ||
"grunt-contrib-watch": "0.6.1", | ||
"grunt-contrib-jshint": "0.11.3", | ||
"grunt-contrib-uglify": "0.9.2", | ||
"grunt-contrib-jasmine": "0.9.2", | ||
"grunt": "1.0.1", | ||
"grunt-notify": "0.4.5", | ||
"grunt-contrib-watch": "1.0.0", | ||
"grunt-contrib-jshint": "1.0.0", | ||
"grunt-contrib-uglify": "1.0.1", | ||
"grunt-contrib-jasmine": "1.0.3", | ||
"grunt-docco": "0.4.0", | ||
"grunt-template-jasmine-istanbul": "0.3.4", | ||
"coveralls": "2.11.4" | ||
"grunt-template-jasmine-istanbul": "0.4.0", | ||
"coveralls": "2.11.9" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -147,3 +147,3 @@ describe("validate.async", function() { | ||
error: new validate.Promise(function(resolve, reject) { | ||
setTimeout(reject.bind(this, "My error"), 1); | ||
setTimeout(resolve.bind(this, "My error"), 1); | ||
}) | ||
@@ -169,19 +169,2 @@ }, { | ||
it.promise("still works with rejecting with an error but logs an error", function() { | ||
spyOn(validate, "error"); | ||
var results = [{ | ||
attribute: "foo", | ||
error: new validate.Promise(function(resolve, reject) { reject("foo"); }) | ||
}]; | ||
return validate.waitForResults(results).then(function() { | ||
expect(results).toEqual([{ | ||
attribute: "foo", | ||
error: "foo" | ||
}]); | ||
expect(validate.error).toHaveBeenCalled(); | ||
}); | ||
}); | ||
it.promise("rejects the promise if any promise throw an exception", function() { | ||
@@ -188,0 +171,0 @@ var results = [{ |
@@ -850,3 +850,2 @@ describe("validate", function() { | ||
describe("collectFormValues", function() { | ||
it("handles empty input", function() { | ||
@@ -988,2 +987,30 @@ expect(validate.collectFormValues()).toEqual({}); | ||
}); | ||
it("handles select tags with 'multiple'", function() { | ||
var form = document.createElement("form"); | ||
form.innerHTML = '' + | ||
'<select name="selected-dropdown" multiple>' + | ||
' <option>' + | ||
' <option value="option1">' + | ||
' <option value="option2" selected>' + | ||
' <option value="option3">' + | ||
' <option value="option4" selected>' + | ||
'</select>' + | ||
'<select name="unselected-dropdown" multiple>' + | ||
' <option>' + | ||
' <option value="option1">' + | ||
' <option value="option2">' + | ||
' <option value="option3">' + | ||
' <option value="option4">' + | ||
'</select>' + | ||
'<select name="empty-value" multiple>' + | ||
' <option selected>' + | ||
'</select>'; | ||
expect(validate.collectFormValues(form)).toEqual({ | ||
"selected-dropdown": ["option2", "option4"], | ||
"unselected-dropdown": [], | ||
"empty-value": [null] | ||
}); | ||
}); | ||
}); | ||
@@ -990,0 +1017,0 @@ |
@@ -272,4 +272,40 @@ describe("validate", function() { | ||
}); | ||
it("deduplicates errors", function() { | ||
var c = { | ||
foo: { | ||
numericality: { | ||
message: "some error" | ||
}, | ||
length: { | ||
is: 23, | ||
wrongLength: "some error" | ||
} | ||
} | ||
}; | ||
expect(validate({foo: "bar"}, c, {format: "flat"})).toHaveItems([ | ||
"Foo some error" | ||
]); | ||
}); | ||
}); | ||
describe("grouped", function() { | ||
it("deduplicates errors", function() { | ||
var c = { | ||
foo: { | ||
numericality: { | ||
message: "some error" | ||
}, | ||
length: { | ||
is: 23, | ||
wrongLength: "some error" | ||
} | ||
} | ||
}; | ||
expect(validate({foo: "bar"}, c)).toEqual({ | ||
foo: ["Foo some error"] | ||
}); | ||
}); | ||
}); | ||
describe("detailedErrors", function() { | ||
@@ -276,0 +312,0 @@ it("allows you to get more info about the errors", function() { |
@@ -47,3 +47,3 @@ describe('validators.datetime', function() { | ||
it("allows empty values", function() { | ||
it("allows undefined values", function() { | ||
spyOn(validate.validators.datetime, "parse"); | ||
@@ -53,4 +53,2 @@ spyOn(validate.validators.datetime, "format"); | ||
expect(datetime(undefined, {})).not.toBeDefined(); | ||
expect(datetime("", {})).not.toBeDefined(); | ||
expect(datetime(" ", {})).not.toBeDefined(); | ||
expect(validate.validators.datetime.parse).not.toHaveBeenCalled(); | ||
@@ -67,2 +65,4 @@ expect(validate.validators.datetime.format).not.toHaveBeenCalled(); | ||
expect(datetime("foobar", {})).toEqual(expected); | ||
expect(datetime("", {})).toEqual(expected); | ||
expect(datetime(" ", {})).toEqual(expected); | ||
}); | ||
@@ -69,0 +69,0 @@ |
@@ -13,4 +13,2 @@ describe('validators.email', function() { | ||
expect(email(undefined, {})).not.toBeDefined(); | ||
expect(email("", {})).not.toBeDefined(); | ||
expect(email(" ", {})).not.toBeDefined(); | ||
}); | ||
@@ -38,2 +36,4 @@ | ||
var expected = "is not a valid email"; | ||
expect(email("", {})).toEqual(expected); | ||
expect(email(" ", {})).toEqual(expected); | ||
expect(email("foobar", {})).toEqual(expected); | ||
@@ -40,0 +40,0 @@ expect(email("foo@bar", {})).toEqual(expected); |
@@ -13,7 +13,7 @@ describe('validators.equality', function() { | ||
expect(equality(undefined, "bar", "foo", {})).not.toBeDefined(); | ||
expect(equality("", "bar", "foo", {})).not.toBeDefined(); | ||
expect(equality(" ", "bar", "foo", {})).not.toBeDefined(); | ||
}); | ||
it("supports equality with another attribute", function() { | ||
expect(equality("", "bar", "foo", {foo: "foo"})).toBeDefined(); | ||
expect(equality(" ", "bar", "foo", {foo: "foo"})).toBeDefined(); | ||
expect(equality("foo", "bar", "foo", {foo: "foo"})).toBeDefined(); | ||
@@ -20,0 +20,0 @@ expect(equality("foo", "bar", "foo", {foo: "foo", bar: "bar"})).toBeDefined(); |
@@ -13,4 +13,2 @@ describe("validators.exclusion", function() { | ||
expect(exclusion(undefined, {})).not.toBeDefined(); | ||
expect(exclusion("", {})).not.toBeDefined(); | ||
expect(exclusion(" ", {})).not.toBeDefined(); | ||
}); | ||
@@ -20,2 +18,4 @@ | ||
var opts = {within: within}; | ||
expect(exclusion("", {})).not.toBeDefined(); | ||
expect(exclusion(" ", {})).not.toBeDefined(); | ||
expect(exclusion("quux", opts)).not.toBeDefined(); | ||
@@ -22,0 +22,0 @@ expect(exclusion(false, opts)).not.toBeDefined(); |
@@ -16,6 +16,2 @@ describe("validators.format", function() { | ||
expect(format(undefined, options2)).not.toBeDefined(); | ||
expect(format("", options1)).not.toBeDefined(); | ||
expect(format("", options2)).not.toBeDefined(); | ||
expect(format(" ", options1)).not.toBeDefined(); | ||
expect(format(" ", options2)).not.toBeDefined(); | ||
}); | ||
@@ -29,2 +25,6 @@ | ||
it("doesn't allow values that doesn't matches the pattern", function() { | ||
expect(format("", options1)).toBeDefined("is invalid"); | ||
expect(format("", options2)).toBeDefined("is invalid"); | ||
expect(format(" ", options1)).toBeDefined("is invalid"); | ||
expect(format(" ", options2)).toBeDefined("is invalid"); | ||
expect(format("barfoo", options1)).toEqual("is invalid"); | ||
@@ -31,0 +31,0 @@ expect(format("barfoo", options2)).toEqual("is invalid"); |
@@ -13,4 +13,2 @@ describe("validators.inclusion", function() { | ||
expect(inclusion(undefined, {})).not.toBeDefined(); | ||
expect(inclusion("", {})).not.toBeDefined(); | ||
expect(inclusion(" ", {})).not.toBeDefined(); | ||
}); | ||
@@ -27,2 +25,4 @@ | ||
var opts = {within: within}; | ||
expect(inclusion("", {})).toBeDefined(); | ||
expect(inclusion(" ", {})).toBeDefined(); | ||
expect(inclusion("quux", opts)).toEqual("^quux is not included in the list"); | ||
@@ -29,0 +29,0 @@ expect(inclusion(false, opts)).toEqual("^false is not included in the list"); |
@@ -86,4 +86,2 @@ describe('validator.length', function() { | ||
expect(length(undefined, options)).not.toBeDefined(); | ||
expect(length("", options)).not.toBeDefined(); | ||
expect(length(" ", options)).not.toBeDefined(); | ||
}); | ||
@@ -107,4 +105,3 @@ | ||
it("allows you to specify is, minimum and maximum", function() { | ||
var value = {length: 9} | ||
, options = { | ||
var options = { | ||
is: 10, | ||
@@ -114,3 +111,6 @@ minimum: 20, | ||
}; | ||
expect(length(value, options)).toHaveLength(3); | ||
expect(length({length: 9}, options)).toHaveLength(3); | ||
expect(length("foobar", options)).toHaveLength(3); | ||
expect(length("", options)).toHaveLength(2); | ||
expect(length(" ", options)).toHaveLength(2); | ||
}); | ||
@@ -117,0 +117,0 @@ |
@@ -7,2 +7,3 @@ describe("validators.numericality", function() { | ||
var n = validate.validators.numericality; | ||
delete n.message; | ||
delete n.notValid; | ||
@@ -24,4 +25,2 @@ delete n.notInteger; | ||
expect(numericality(undefined, {})).not.toBeDefined(); | ||
expect(numericality("", {})).not.toBeDefined(); | ||
expect(numericality(" ", {})).not.toBeDefined(); | ||
}); | ||
@@ -36,2 +35,4 @@ | ||
var e = "is not a number"; | ||
expect(numericality("", {})).toEqual(e); | ||
expect(numericality(" ", {})).toEqual(e); | ||
expect(numericality("foo", {})).toEqual(e); | ||
@@ -55,2 +56,4 @@ expect(numericality(NaN, {})).toEqual(e); | ||
it("uses the custom message if specified", function() { | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality("foo", {})).toEqual("default generic message"); | ||
var expected = "default message"; | ||
@@ -74,2 +77,5 @@ expect(numericality("foo", {notValid: expected})).toEqual("default message"); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.14, opts)).toEqual("default generic message"); | ||
validate.validators.numericality.notInteger = "default message"; | ||
@@ -105,5 +111,7 @@ expect(numericality(3.14, opts)).toEqual("default message"); | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notGreaterThan = expected; | ||
expect(numericality(3.14, {greaterThan: 3.14})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.14, {greaterThan: 3.14})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notGreaterThan = "default message"; | ||
expect(numericality(3.14, {greaterThan: 3.14})).toEqual(["default message"]); | ||
}); | ||
@@ -129,5 +137,7 @@ }); | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notGreaterThanOrEqualTo = expected; | ||
expect(numericality(3.13, {greaterThanOrEqualTo: 3.14})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.13, {greaterThanOrEqualTo: 3.14})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notGreaterThanOrEqualTo = "default message"; | ||
expect(numericality(3.13, {greaterThanOrEqualTo: 3.14})).toEqual(["default message"]); | ||
}); | ||
@@ -147,5 +157,7 @@ }); | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notEqualTo = expected; | ||
expect(numericality(3.13, {equalTo: 3.14})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.13, {equalTo: 3.14})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notEqualTo = "default message"; | ||
expect(numericality(3.13, {equalTo: 3.14})).toEqual(["default message"]); | ||
}); | ||
@@ -171,5 +183,7 @@ | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notLessThan = expected; | ||
expect(numericality(3.14, {lessThan: 3.14})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.14, {lessThan: 3.14})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notLessThan = "default message"; | ||
expect(numericality(3.14, {lessThan: 3.14})).toEqual(["default message"]); | ||
}); | ||
@@ -195,5 +209,7 @@ | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notLessThanOrEqualTo = expected; | ||
expect(numericality(3.15, {lessThanOrEqualTo: 3.14})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3.15, {lessThanOrEqualTo: 3.14})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notLessThanOrEqualTo = "default message"; | ||
expect(numericality(3.15, {lessThanOrEqualTo: 3.14})).toEqual(["default message"]); | ||
}); | ||
@@ -220,5 +236,7 @@ | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notDivisibleBy = expected; | ||
expect(numericality(161, {divisibleBy: 200})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(161, {divisibleBy: 200})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notDivisibleBy = "default message"; | ||
expect(numericality(161, {divisibleBy: 200})).toEqual(["default message"]); | ||
}); | ||
@@ -247,5 +265,7 @@ | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notOdd = expected; | ||
expect(numericality(2, {odd: true})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(2, {odd: true})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notOdd = "default message"; | ||
expect(numericality(2, {odd: true})).toEqual(["default message"]); | ||
}); | ||
@@ -274,5 +294,7 @@ | ||
it("allows for a default message", function() { | ||
var expected = "default message"; | ||
validate.validators.numericality.notEven = expected; | ||
expect(numericality(3, {even: true})).toEqual([expected]); | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality(3, {even: true})).toEqual(["default generic message"]); | ||
validate.validators.numericality.notEven = "default message"; | ||
expect(numericality(3, {even: true})).toEqual(["default message"]); | ||
}); | ||
@@ -364,2 +386,14 @@ | ||
}); | ||
it("allows overriding the generic message", function() { | ||
validate.validators.numericality.message = "default generic message"; | ||
expect(numericality("foo", {})).toEqual("default generic message"); | ||
validate.validators.numericality.notValid = "default not valid message"; | ||
expect(numericality("foo", {})).toEqual("default not valid message"); | ||
expect(numericality("foo", {notValid: "not valid"})).toEqual("not valid"); | ||
expect(numericality("foo", {message: "some error"})).toEqual("some error"); | ||
}); | ||
}); |
@@ -32,2 +32,9 @@ describe('validator.presence', function() { | ||
it("has an option for allowing empty values", function() { | ||
expect(presence('', {allowEmpty: true})).not.toBeDefined(); | ||
expect(presence(' ', {allowEmpty: true})).not.toBeDefined(); | ||
expect(presence([], {allowEmpty: true})).not.toBeDefined(); | ||
expect(presence({}, {allowEmpty: true})).not.toBeDefined(); | ||
}); | ||
it("also allows to specify your own nice message", function() { | ||
@@ -34,0 +41,0 @@ validate.validators.presence.message = "default message"; |
@@ -13,4 +13,2 @@ describe("validators.url", function() { | ||
expect(url(undefined, {})).not.toBeDefined(); | ||
expect(url("", {})).not.toBeDefined(); | ||
expect(url(" ", {})).not.toBeDefined(); | ||
}); | ||
@@ -27,2 +25,4 @@ | ||
expect(url("", {})).toBeDefined(); | ||
expect(url(" ", {})).toBeDefined(); | ||
expect(url("http://", {})).toBeDefined(); | ||
@@ -52,3 +52,2 @@ expect(url("http://.", {})).toBeDefined(); | ||
expect(url("http://-error-.invalid/", {})).toBeDefined(); | ||
expect(url("http://a.b--c.de/", {})).toBeDefined(); | ||
expect(url("http://-a.b.co", {})).toBeDefined(); | ||
@@ -71,2 +70,4 @@ expect(url("http://a.b-.co", {})).toBeDefined(); | ||
it("allows valid urls", function() { | ||
expect(url("http://foo.com", {})).not.toBeDefined(); | ||
expect(url("http://foo.com/", {})).not.toBeDefined(); | ||
expect(url("http://foo.com/blah_blah", {})).not.toBeDefined(); | ||
@@ -76,4 +77,7 @@ expect(url("http://foo.com/blah_blah/", {})).not.toBeDefined(); | ||
expect(url("http://foo.com/blah_blah_(wikipedia)_(again)", {})).not.toBeDefined(); | ||
expect(url("http://foo.com?query=bar", {})).not.toBeDefined(); | ||
expect(url("http://foo.com#fragment=bar", {})).not.toBeDefined(); | ||
expect(url("http://www.example.com/wpstyle/?p=364", {})).not.toBeDefined(); | ||
expect(url("https://www.example.com/foo/?bar=baz&inga=42&quux", {})).not.toBeDefined(); | ||
expect(url("https://www.example.com/foo/#bar=baz&inga=42&quux", {})).not.toBeDefined(); | ||
expect(url("http://✪df.ws/123", {})).not.toBeDefined(); | ||
@@ -108,2 +112,3 @@ expect(url("http://userid:password@example.com:8080", {})).not.toBeDefined(); | ||
expect(url("http://223.255.255.254", {})).not.toBeDefined(); | ||
expect(url("http://a.b--c.de/", {})).not.toBeDefined(); | ||
}); | ||
@@ -110,0 +115,0 @@ |
186
validate.js
/*! | ||
* validate.js 0.10.0 | ||
* validate.js 0.11.0 | ||
* | ||
@@ -59,3 +59,3 @@ * (c) 2013-2016 Nicklas Ansman, 2013 Wrapp | ||
major: 0, | ||
minor: 10, | ||
minor: 11, | ||
patch: 0, | ||
@@ -150,4 +150,2 @@ metadata: null, | ||
processValidationResults: function(errors, options) { | ||
var attr; | ||
errors = v.pruneEmptyErrors(errors, options); | ||
@@ -157,20 +155,8 @@ errors = v.expandMultipleErrors(errors, options); | ||
switch (options.format || "grouped") { | ||
case "detailed": | ||
// Do nothing more to the errors | ||
break; | ||
var format = options.format || "grouped"; | ||
case "flat": | ||
errors = v.flattenErrorsToArray(errors); | ||
break; | ||
case "grouped": | ||
errors = v.groupErrorsByAttribute(errors); | ||
for (attr in errors) { | ||
errors[attr] = v.flattenErrorsToArray(errors[attr]); | ||
} | ||
break; | ||
default: | ||
throw new Error(v.format("Unknown format %{format}", options)); | ||
if (typeof v.formatters[format] === 'function') { | ||
errors = v.formatters[format](errors); | ||
} else { | ||
throw new Error(v.format("Unknown format %{format}", options)); | ||
} | ||
@@ -235,14 +221,5 @@ | ||
return memo.then(function() { | ||
return result.error.then( | ||
function(error) { | ||
result.error = error || null; | ||
}, | ||
function(error) { | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
v.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead."); | ||
result.error = error; | ||
} | ||
); | ||
return result.error.then(function(error) { | ||
result.error = error || null; | ||
}); | ||
}); | ||
@@ -539,4 +516,6 @@ }, new v.Promise(function(r) { r(); })); // A resolved promise | ||
, i | ||
, j | ||
, input | ||
, inputs | ||
, option | ||
, value; | ||
@@ -584,3 +563,13 @@ | ||
input = inputs.item(i); | ||
value = v.sanitizeFormValue(input.options[input.selectedIndex].value, options); | ||
if (input.multiple) { | ||
value = []; | ||
for (j in input.options) { | ||
option = input.options[j]; | ||
if (option.selected) { | ||
value.push(v.sanitizeFormValue(option.value, options)); | ||
} | ||
} | ||
} else { | ||
value = v.sanitizeFormValue(input.options[input.selectedIndex].value, options); | ||
} | ||
values[input.name] = value; | ||
@@ -692,3 +681,7 @@ } | ||
flattenErrorsToArray: function(errors) { | ||
return errors.map(function(error) { return error.error; }); | ||
return errors | ||
.map(function(error) { return error.error; }) | ||
.filter(function(value, index, self) { | ||
return self.indexOf(value) === index; | ||
}); | ||
}, | ||
@@ -777,3 +770,3 @@ | ||
options = v.extend({}, this.options, options); | ||
if (v.isEmpty(value)) { | ||
if (options.allowEmpty ? !v.isDefined(value) : v.isEmpty(value)) { | ||
return options.message || this.message || "can't be blank"; | ||
@@ -784,3 +777,3 @@ } | ||
// Empty values are allowed | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -833,3 +826,3 @@ } | ||
// Empty values are fine | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -861,3 +854,7 @@ } | ||
if (!(new RegExp(pattern).test(value))) { | ||
return options.message || options.notValid || this.notValid || "must be a valid number"; | ||
return options.message || | ||
options.notValid || | ||
this.notValid || | ||
this.message || | ||
"must be a valid number"; | ||
} | ||
@@ -867,3 +864,3 @@ } | ||
// Coerce the value to a number unless we're being strict. | ||
if (options.noStrings !== true && v.isString(value)) { | ||
if (options.noStrings !== true && v.isString(value) && !v.isEmpty(value)) { | ||
value = +value; | ||
@@ -874,3 +871,7 @@ } | ||
if (!v.isNumber(value)) { | ||
return options.message || options.notValid || this.notValid || "is not a number"; | ||
return options.message || | ||
options.notValid || | ||
this.notValid || | ||
this.message || | ||
"is not a number"; | ||
} | ||
@@ -881,3 +882,7 @@ | ||
if (options.onlyInteger && !v.isInteger(value)) { | ||
return options.message || options.notInteger || this.notInteger || "must be an integer"; | ||
return options.message || | ||
options.notInteger || | ||
this.notInteger || | ||
this.message || | ||
"must be an integer"; | ||
} | ||
@@ -892,3 +897,6 @@ | ||
var key = "not" + v.capitalize(name); | ||
var msg = options[key] || this[key] || "must be %{type} %{count}"; | ||
var msg = options[key] || | ||
this[key] || | ||
this.message || | ||
"must be %{type} %{count}"; | ||
@@ -903,6 +911,12 @@ errors.push(v.format(msg, { | ||
if (options.odd && value % 2 !== 1) { | ||
errors.push(options.notOdd || this.notOdd || "must be odd"); | ||
errors.push(options.notOdd || | ||
this.notOdd || | ||
this.message || | ||
"must be odd"); | ||
} | ||
if (options.even && value % 2 !== 0) { | ||
errors.push(options.notEven || this.notEven || "must be even"); | ||
errors.push(options.notEven || | ||
this.notEven || | ||
this.message || | ||
"must be even"); | ||
} | ||
@@ -920,3 +934,3 @@ | ||
// Empty values are fine | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -991,3 +1005,3 @@ } | ||
// Empty values are allowed | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1009,3 +1023,3 @@ } | ||
// Empty values are fine | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1027,3 +1041,3 @@ } | ||
// Empty values are fine | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1045,3 +1059,3 @@ } | ||
// Empty values are fine | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1059,3 +1073,3 @@ } | ||
equality: function(value, options, attribute, attributes) { | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1089,3 +1103,3 @@ } | ||
url: function(value, options) { | ||
if (v.isEmpty(value)) { | ||
if (!v.isDefined(value)) { | ||
return; | ||
@@ -1107,34 +1121,27 @@ } | ||
"^" + | ||
// schemes | ||
"(?:(?:" + schemes.join("|") + "):\\/\\/)" + | ||
// credentials | ||
"(?:\\S+(?::\\S*)?@)?"; | ||
// protocol identifier | ||
"(?:(?:" + schemes.join("|") + ")://)" + | ||
// user:pass authentication | ||
"(?:\\S+(?::\\S*)?@)?" + | ||
"(?:"; | ||
regex += "(?:"; | ||
var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))"; | ||
// This ia a special case for the localhost hostname | ||
if (allowLocal) { | ||
tld += "?"; | ||
} else { | ||
// private & local addresses | ||
regex += | ||
"(?!10(?:\\.\\d{1,3}){3})" + | ||
"(?!127(?:\\.\\d{1,3}){3})" + | ||
"(?!169\\.254(?:\\.\\d{1,3}){2})" + | ||
"(?!192\\.168(?:\\.\\d{1,3}){2})" + | ||
"(?!172" + | ||
"\\.(?:1[6-9]|2\\d|3[0-1])" + | ||
"(?:\\.\\d{1,3})" + | ||
"{2})"; | ||
// IP address exclusion | ||
// private & local networks | ||
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" + | ||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + | ||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})"; | ||
} | ||
var hostname = | ||
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" + | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" + | ||
tld + ")"; | ||
// reserved addresses | ||
regex += | ||
// IP address dotted notation octets | ||
// excludes loopback network 0.0.0.0 | ||
// excludes reserved space >= 224.0.0.0 | ||
// excludes network & broacast addresses | ||
// (first & last IP address of each class) | ||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + | ||
@@ -1144,8 +1151,13 @@ "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + | ||
"|" + | ||
hostname + | ||
// port number | ||
"(?::\\d{2,5})?" + | ||
// path | ||
"(?:\\/[^\\s]*)?" + | ||
"$"; | ||
// host name | ||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" + | ||
// domain name | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" + | ||
tld + | ||
")" + | ||
// port number | ||
"(?::\\d{2,5})?" + | ||
// resource path | ||
"(?:[/?#]\\S*)?" + | ||
"$"; | ||
@@ -1159,2 +1171,16 @@ var PATTERN = new RegExp(regex, 'i'); | ||
validate.formatters = { | ||
detailed: function(errors) {return errors;}, | ||
flat: v.flattenErrorsToArray, | ||
grouped: function(errors) { | ||
var attr; | ||
errors = v.groupErrorsByAttribute(errors); | ||
for (attr in errors) { | ||
errors[attr] = v.flattenErrorsToArray(errors[attr]); | ||
} | ||
return errors; | ||
} | ||
}; | ||
validate.exposeModule(validate, this, exports, module, define); | ||
@@ -1161,0 +1187,0 @@ }).call(this, |
/*! | ||
* validate.js 0.10.0 | ||
* validate.js 0.11.0 | ||
* http://validatejs.org/ | ||
@@ -8,3 +8,3 @@ * (c) 2013-2015 Nicklas Ansman, 2013 Wrapp | ||
(function(a,b,c){"use strict";var d=function(a,b,c){c=e.extend({},e.options,c);var f,g,h=e.runValidations(a,b,c);for(f in h)for(g in h[f])if(e.isPromise(h[f][g]))throw new Error("Use validate.async if you want support for promises");return d.processValidationResults(h,c)},e=d;e.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},e.extend(d,{version:{major:0,minor:10,patch:0,metadata:null,toString:function(){var a=e.format("%{major}.%{minor}.%{patch}",e.version);return e.isEmpty(e.version.metadata)||(a+="+"+e.version.metadata),a}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(a,b,c){var d,f,g,h,i,j,k,l=[];(e.isDomElement(a)||e.isJqueryElement(a))&&(a=e.collectFormValues(a));for(d in b){g=e.getDeepObjectValue(a,d),h=e.result(b[d],g,a,d,c,b);for(f in h){if(i=e.validators[f],!i)throw k=e.format("Unknown validator %{name}",{name:f}),new Error(k);j=h[f],j=e.result(j,g,a,d,c,b),j&&l.push({attribute:d,value:g,validator:f,globalOptions:c,attributes:a,options:j,error:i.call(i,g,j,d,a,c)})}}return l},processValidationResults:function(a,b){var c;switch(a=e.pruneEmptyErrors(a,b),a=e.expandMultipleErrors(a,b),a=e.convertErrorMessages(a,b),b.format||"grouped"){case"detailed":break;case"flat":a=e.flattenErrorsToArray(a);break;case"grouped":a=e.groupErrorsByAttribute(a);for(c in a)a[c]=e.flattenErrorsToArray(a[c]);break;default:throw new Error(e.format("Unknown format %{format}",b))}return e.isEmpty(a)?void 0:a},async:function(a,b,c){c=e.extend({},e.async.options,c);var d=c.wrapErrors||function(a){return a};c.cleanAttributes!==!1&&(a=e.cleanAttributes(a,b));var f=e.runValidations(a,b,c);return new e.Promise(function(g,h){e.waitForResults(f).then(function(){var i=e.processValidationResults(f,c);i?h(new d(i,c,a,b)):g(a)},function(a){h(a)})})},single:function(a,b,c){return c=e.extend({},e.single.options,c,{format:"flat",fullMessages:!1}),e({single:a},{single:b},c)},waitForResults:function(a){return a.reduce(function(a,b){return e.isPromise(b.error)?a.then(function(){return b.error.then(function(a){b.error=a||null},function(a){if(a instanceof Error)throw a;e.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead."),b.error=a})}):a},new e.Promise(function(a){a()}))},result:function(a){var b=[].slice.call(arguments,1);return"function"==typeof a&&(a=a.apply(null,b)),a},isNumber:function(a){return"number"==typeof a&&!isNaN(a)},isFunction:function(a){return"function"==typeof a},isInteger:function(a){return e.isNumber(a)&&a%1===0},isBoolean:function(a){return"boolean"==typeof a},isObject:function(a){return a===Object(a)},isDate:function(a){return a instanceof Date},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&e.isFunction(a.then)},isJqueryElement:function(a){return a&&e.isString(a.jquery)},isDomElement:function(a){return a&&a.querySelectorAll&&a.querySelector?e.isObject(document)&&a===document?!0:"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName:!1},isEmpty:function(a){var b;if(!e.isDefined(a))return!0;if(e.isFunction(a))return!1;if(e.isString(a))return e.EMPTY_STRING_REGEXP.test(a);if(e.isArray(a))return 0===a.length;if(e.isDate(a))return!1;if(e.isObject(a)){for(b in a)return!1;return!0}return!1},format:e.extend(function(a,b){return e.isString(a)?a.replace(e.format.FORMAT_REGEXP,function(a,c,d){return"%"===c?"%{"+d+"}":String(b[d])}):a},{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(a){return e.isNumber(a)?100*a%1===0?""+a:parseFloat(Math.round(100*a)/100).toFixed(2):e.isArray(a)?a.map(function(a){return e.prettify(a)}).join(", "):e.isObject(a)?a.toString():(a=""+a,a.replace(/([^\s])\.([^\s])/g,"$1 $2").replace(/\\+/g,"").replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,function(a,b,c){return""+b+" "+c.toLowerCase()}).toLowerCase())},stringifyValue:function(a){return e.prettify(a)},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},isHash:function(a){return e.isObject(a)&&!e.isArray(a)&&!e.isFunction(a)},contains:function(a,b){return e.isDefined(a)?e.isArray(a)?-1!==a.indexOf(b):b in a:!1},unique:function(a){return e.isArray(a)?a.filter(function(a,b,c){return c.indexOf(a)==b}):a},forEachKeyInKeypath:function(a,b,c){if(e.isString(b)){var d,f="",g=!1;for(d=0;d<b.length;++d)switch(b[d]){case".":g?(g=!1,f+="."):(a=c(a,f,!1),f="");break;case"\\":g?(g=!1,f+="\\"):g=!0;break;default:g=!1,f+=b[d]}return c(a,f,!0)}},getDeepObjectValue:function(a,b){return e.isObject(a)?e.forEachKeyInKeypath(a,b,function(a,b){return e.isObject(a)?a[b]:void 0}):void 0},collectFormValues:function(a,b){var c,d,f,g,h={};if(e.isJqueryElement(a)&&(a=a[0]),!a)return h;for(b=b||{},f=a.querySelectorAll("input[name], textarea[name]"),c=0;c<f.length;++c)d=f.item(c),e.isDefined(d.getAttribute("data-ignored"))||(g=e.sanitizeFormValue(d.value,b),"number"===d.type?g=g?+g:null:"checkbox"===d.type?d.attributes.value?d.checked||(g=h[d.name]||null):g=d.checked:"radio"===d.type&&(d.checked||(g=h[d.name]||null)),h[d.name]=g);for(f=a.querySelectorAll("select[name]"),c=0;c<f.length;++c)d=f.item(c),g=e.sanitizeFormValue(d.options[d.selectedIndex].value,b),h[d.name]=g;return h},sanitizeFormValue:function(a,b){return b.trim&&e.isString(a)&&(a=a.trim()),b.nullify!==!1&&""===a?null:a},capitalize:function(a){return e.isString(a)?a[0].toUpperCase()+a.slice(1):a},pruneEmptyErrors:function(a){return a.filter(function(a){return!e.isEmpty(a.error)})},expandMultipleErrors:function(a){var b=[];return a.forEach(function(a){e.isArray(a.error)?a.error.forEach(function(c){b.push(e.extend({},a,{error:c}))}):b.push(a)}),b},convertErrorMessages:function(a,b){b=b||{};var c=[];return a.forEach(function(a){var d=e.result(a.error,a.value,a.attribute,a.options,a.attributes,a.globalOptions);return e.isString(d)?("^"===d[0]?d=d.slice(1):b.fullMessages!==!1&&(d=e.capitalize(e.prettify(a.attribute))+" "+d),d=d.replace(/\\\^/g,"^"),d=e.format(d,{value:e.stringifyValue(a.value)}),void c.push(e.extend({},a,{error:d}))):void c.push(a)}),c},groupErrorsByAttribute:function(a){var b={};return a.forEach(function(a){var c=b[a.attribute];c?c.push(a):b[a.attribute]=[a]}),b},flattenErrorsToArray:function(a){return a.map(function(a){return a.error})},cleanAttributes:function(a,b){function c(a,b,c){return e.isObject(a[b])?a[b]:a[b]=c?!0:{}}function d(a){var b,d={};for(b in a)a[b]&&e.forEachKeyInKeypath(d,b,c);return d}function f(a,b){if(!e.isObject(a))return a;var c,d,g=e.extend({},a);for(d in a)c=b[d],e.isObject(c)?g[d]=f(g[d],c):c||delete g[d];return g}return e.isObject(b)&&e.isObject(a)?(b=d(b),f(a,b)):{}},exposeModule:function(a,b,c,d,e){c?(d&&d.exports&&(c=d.exports=a),c.validate=a):(b.validate=a,a.isFunction(e)&&e.amd&&e([],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn("[validate.js] "+a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error("[validate.js] "+a)}}),d.validators={presence:function(a,b){return b=e.extend({},this.options,b),e.isEmpty(a)?b.message||this.message||"can't be blank":void 0},length:function(a,b,c){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var d,f=b.is,g=b.maximum,h=b.minimum,i=b.tokenizer||function(a){return a},j=[];a=i(a);var k=a.length;return e.isNumber(k)?(e.isNumber(f)&&k!==f&&(d=b.wrongLength||this.wrongLength||"is the wrong length (should be %{count} characters)",j.push(e.format(d,{count:f}))),e.isNumber(h)&&h>k&&(d=b.tooShort||this.tooShort||"is too short (minimum is %{count} characters)",j.push(e.format(d,{count:h}))),e.isNumber(g)&&k>g&&(d=b.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",j.push(e.format(d,{count:g}))),j.length>0?b.message||j:void 0):(e.error(e.format("Attribute %{attr} has a non numeric value for `length`",{attr:c})),b.message||this.notValid||"has an incorrect length")}},numericality:function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d,f=[],g={greaterThan:function(a,b){return a>b},greaterThanOrEqualTo:function(a,b){return a>=b},equalTo:function(a,b){return a===b},lessThan:function(a,b){return b>a},lessThanOrEqualTo:function(a,b){return b>=a},divisibleBy:function(a,b){return a%b===0}};if(e.isString(a)&&b.strict){var h="^(0|[1-9]\\d*)";if(b.onlyInteger||(h+="(\\.\\d+)?"),h+="$",!new RegExp(h).test(a))return b.message||b.notValid||this.notValid||"must be a valid number"}if(b.noStrings!==!0&&e.isString(a)&&(a=+a),!e.isNumber(a))return b.message||b.notValid||this.notValid||"is not a number";if(b.onlyInteger&&!e.isInteger(a))return b.message||b.notInteger||this.notInteger||"must be an integer";for(c in g)if(d=b[c],e.isNumber(d)&&!g[c](a,d)){var i="not"+e.capitalize(c),j=b[i]||this[i]||"must be %{type} %{count}";f.push(e.format(j,{count:d,type:e.prettify(c)}))}return b.odd&&a%2!==1&&f.push(b.notOdd||this.notOdd||"must be odd"),b.even&&a%2!==0&&f.push(b.notEven||this.notEven||"must be even"),f.length?b.message||f:void 0}},datetime:e.extend(function(a,b){if(!e.isFunction(this.parse)||!e.isFunction(this.format))throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d=[],f=b.earliest?this.parse(b.earliest,b):NaN,g=b.latest?this.parse(b.latest,b):NaN;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?(c=b.notValid||b.message||this.notValid||"must be a valid date",e.format(c,{value:arguments[0]})):(!isNaN(f)&&f>a&&(c=b.tooEarly||b.message||this.tooEarly||"must be no earlier than %{date}",c=e.format(c,{value:this.format(a,b),date:this.format(f,b)}),d.push(c)),!isNaN(g)&&a>g&&(c=b.tooLate||b.message||this.tooLate||"must be no later than %{date}",c=e.format(c,{date:this.format(g,b),value:this.format(a,b)}),d.push(c)),d.length?e.unique(d):void 0)}},{parse:null,format:null}),date:function(a,b){return b=e.extend({},b,{dateOnly:!0}),e.validators.datetime.call(e.validators.datetime,a,b)},format:function(a,b){(e.isString(b)||b instanceof RegExp)&&(b={pattern:b}),b=e.extend({},this.options,b);var c,d=b.message||this.message||"is invalid",f=b.pattern;return e.isEmpty(a)?void 0:e.isString(a)?(e.isString(f)&&(f=new RegExp(b.pattern,b.flags)),c=f.exec(a),c&&c[0].length==a.length?void 0:d):d},inclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),!e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is not included in the list";return e.format(c,{value:a})}},exclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is restricted";return e.format(c,{value:a})}},email:e.extend(function(a,b){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid email";if(!e.isEmpty(a))return e.isString(a)&&this.PATTERN.exec(a)?void 0:c},{PATTERN:/^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i}),equality:function(a,b,c,d){if(!e.isEmpty(a)){e.isString(b)&&(b={attribute:b}),b=e.extend({},this.options,b);var f=b.message||this.message||"is not equal to %{attribute}";if(e.isEmpty(b.attribute)||!e.isString(b.attribute))throw new Error("The attribute must be a non empty string");var g=e.getDeepObjectValue(d,b.attribute),h=b.comparator||function(a,b){return a===b};return h(a,g,b,c,d)?void 0:e.format(f,{attribute:e.prettify(b.attribute)})}},url:function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid url",d=b.schemes||this.schemes||["http","https"],f=b.allowLocal||this.allowLocal||!1;if(!e.isString(a))return c;var g="^(?:(?:"+d.join("|")+"):\\/\\/)(?:\\S+(?::\\S*)?@)?";g+="(?:";var h="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";f?h+="?":g+="(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})";var i="(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*"+h+")";g+="(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|"+i+"(?::\\d{2,5})?(?:\\/[^\\s]*)?$";var j=new RegExp(g,"i");return j.exec(a)?void 0:c}}},d.exposeModule(d,this,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define:null); | ||
(function(a,b,c){"use strict";var d=function(a,b,c){c=e.extend({},e.options,c);var f,g,h=e.runValidations(a,b,c);for(f in h)for(g in h[f])if(e.isPromise(h[f][g]))throw new Error("Use validate.async if you want support for promises");return d.processValidationResults(h,c)},e=d;e.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},e.extend(d,{version:{major:0,minor:11,patch:0,metadata:null,toString:function(){var a=e.format("%{major}.%{minor}.%{patch}",e.version);return e.isEmpty(e.version.metadata)||(a+="+"+e.version.metadata),a}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(a,b,c){var d,f,g,h,i,j,k,l=[];(e.isDomElement(a)||e.isJqueryElement(a))&&(a=e.collectFormValues(a));for(d in b){g=e.getDeepObjectValue(a,d),h=e.result(b[d],g,a,d,c,b);for(f in h){if(i=e.validators[f],!i)throw k=e.format("Unknown validator %{name}",{name:f}),new Error(k);j=h[f],j=e.result(j,g,a,d,c,b),j&&l.push({attribute:d,value:g,validator:f,globalOptions:c,attributes:a,options:j,error:i.call(i,g,j,d,a,c)})}}return l},processValidationResults:function(a,b){a=e.pruneEmptyErrors(a,b),a=e.expandMultipleErrors(a,b),a=e.convertErrorMessages(a,b);var c=b.format||"grouped";if("function"!=typeof e.formatters[c])throw new Error(e.format("Unknown format %{format}",b));return a=e.formatters[c](a),e.isEmpty(a)?void 0:a},async:function(a,b,c){c=e.extend({},e.async.options,c);var d=c.wrapErrors||function(a){return a};c.cleanAttributes!==!1&&(a=e.cleanAttributes(a,b));var f=e.runValidations(a,b,c);return new e.Promise(function(g,h){e.waitForResults(f).then(function(){var i=e.processValidationResults(f,c);i?h(new d(i,c,a,b)):g(a)},function(a){h(a)})})},single:function(a,b,c){return c=e.extend({},e.single.options,c,{format:"flat",fullMessages:!1}),e({single:a},{single:b},c)},waitForResults:function(a){return a.reduce(function(a,b){return e.isPromise(b.error)?a.then(function(){return b.error.then(function(a){b.error=a||null})}):a},new e.Promise(function(a){a()}))},result:function(a){var b=[].slice.call(arguments,1);return"function"==typeof a&&(a=a.apply(null,b)),a},isNumber:function(a){return"number"==typeof a&&!isNaN(a)},isFunction:function(a){return"function"==typeof a},isInteger:function(a){return e.isNumber(a)&&a%1===0},isBoolean:function(a){return"boolean"==typeof a},isObject:function(a){return a===Object(a)},isDate:function(a){return a instanceof Date},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&e.isFunction(a.then)},isJqueryElement:function(a){return a&&e.isString(a.jquery)},isDomElement:function(a){return a&&a.querySelectorAll&&a.querySelector?e.isObject(document)&&a===document?!0:"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName:!1},isEmpty:function(a){var b;if(!e.isDefined(a))return!0;if(e.isFunction(a))return!1;if(e.isString(a))return e.EMPTY_STRING_REGEXP.test(a);if(e.isArray(a))return 0===a.length;if(e.isDate(a))return!1;if(e.isObject(a)){for(b in a)return!1;return!0}return!1},format:e.extend(function(a,b){return e.isString(a)?a.replace(e.format.FORMAT_REGEXP,function(a,c,d){return"%"===c?"%{"+d+"}":String(b[d])}):a},{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(a){return e.isNumber(a)?100*a%1===0?""+a:parseFloat(Math.round(100*a)/100).toFixed(2):e.isArray(a)?a.map(function(a){return e.prettify(a)}).join(", "):e.isObject(a)?a.toString():(a=""+a,a.replace(/([^\s])\.([^\s])/g,"$1 $2").replace(/\\+/g,"").replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,function(a,b,c){return""+b+" "+c.toLowerCase()}).toLowerCase())},stringifyValue:function(a){return e.prettify(a)},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},isHash:function(a){return e.isObject(a)&&!e.isArray(a)&&!e.isFunction(a)},contains:function(a,b){return e.isDefined(a)?e.isArray(a)?-1!==a.indexOf(b):b in a:!1},unique:function(a){return e.isArray(a)?a.filter(function(a,b,c){return c.indexOf(a)==b}):a},forEachKeyInKeypath:function(a,b,c){if(e.isString(b)){var d,f="",g=!1;for(d=0;d<b.length;++d)switch(b[d]){case".":g?(g=!1,f+="."):(a=c(a,f,!1),f="");break;case"\\":g?(g=!1,f+="\\"):g=!0;break;default:g=!1,f+=b[d]}return c(a,f,!0)}},getDeepObjectValue:function(a,b){return e.isObject(a)?e.forEachKeyInKeypath(a,b,function(a,b){return e.isObject(a)?a[b]:void 0}):void 0},collectFormValues:function(a,b){var c,d,f,g,h,i,j={};if(e.isJqueryElement(a)&&(a=a[0]),!a)return j;for(b=b||{},g=a.querySelectorAll("input[name], textarea[name]"),c=0;c<g.length;++c)f=g.item(c),e.isDefined(f.getAttribute("data-ignored"))||(i=e.sanitizeFormValue(f.value,b),"number"===f.type?i=i?+i:null:"checkbox"===f.type?f.attributes.value?f.checked||(i=j[f.name]||null):i=f.checked:"radio"===f.type&&(f.checked||(i=j[f.name]||null)),j[f.name]=i);for(g=a.querySelectorAll("select[name]"),c=0;c<g.length;++c){if(f=g.item(c),f.multiple){i=[];for(d in f.options)h=f.options[d],h.selected&&i.push(e.sanitizeFormValue(h.value,b))}else i=e.sanitizeFormValue(f.options[f.selectedIndex].value,b);j[f.name]=i}return j},sanitizeFormValue:function(a,b){return b.trim&&e.isString(a)&&(a=a.trim()),b.nullify!==!1&&""===a?null:a},capitalize:function(a){return e.isString(a)?a[0].toUpperCase()+a.slice(1):a},pruneEmptyErrors:function(a){return a.filter(function(a){return!e.isEmpty(a.error)})},expandMultipleErrors:function(a){var b=[];return a.forEach(function(a){e.isArray(a.error)?a.error.forEach(function(c){b.push(e.extend({},a,{error:c}))}):b.push(a)}),b},convertErrorMessages:function(a,b){b=b||{};var c=[];return a.forEach(function(a){var d=e.result(a.error,a.value,a.attribute,a.options,a.attributes,a.globalOptions);return e.isString(d)?("^"===d[0]?d=d.slice(1):b.fullMessages!==!1&&(d=e.capitalize(e.prettify(a.attribute))+" "+d),d=d.replace(/\\\^/g,"^"),d=e.format(d,{value:e.stringifyValue(a.value)}),void c.push(e.extend({},a,{error:d}))):void c.push(a)}),c},groupErrorsByAttribute:function(a){var b={};return a.forEach(function(a){var c=b[a.attribute];c?c.push(a):b[a.attribute]=[a]}),b},flattenErrorsToArray:function(a){return a.map(function(a){return a.error}).filter(function(a,b,c){return c.indexOf(a)===b})},cleanAttributes:function(a,b){function c(a,b,c){return e.isObject(a[b])?a[b]:a[b]=c?!0:{}}function d(a){var b,d={};for(b in a)a[b]&&e.forEachKeyInKeypath(d,b,c);return d}function f(a,b){if(!e.isObject(a))return a;var c,d,g=e.extend({},a);for(d in a)c=b[d],e.isObject(c)?g[d]=f(g[d],c):c||delete g[d];return g}return e.isObject(b)&&e.isObject(a)?(b=d(b),f(a,b)):{}},exposeModule:function(a,b,c,d,e){c?(d&&d.exports&&(c=d.exports=a),c.validate=a):(b.validate=a,a.isFunction(e)&&e.amd&&e([],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn("[validate.js] "+a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error("[validate.js] "+a)}}),d.validators={presence:function(a,b){return b=e.extend({},this.options,b),(b.allowEmpty?!e.isDefined(a):e.isEmpty(a))?b.message||this.message||"can't be blank":void 0},length:function(a,b,c){if(e.isDefined(a)){b=e.extend({},this.options,b);var d,f=b.is,g=b.maximum,h=b.minimum,i=b.tokenizer||function(a){return a},j=[];a=i(a);var k=a.length;return e.isNumber(k)?(e.isNumber(f)&&k!==f&&(d=b.wrongLength||this.wrongLength||"is the wrong length (should be %{count} characters)",j.push(e.format(d,{count:f}))),e.isNumber(h)&&h>k&&(d=b.tooShort||this.tooShort||"is too short (minimum is %{count} characters)",j.push(e.format(d,{count:h}))),e.isNumber(g)&&k>g&&(d=b.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",j.push(e.format(d,{count:g}))),j.length>0?b.message||j:void 0):(e.error(e.format("Attribute %{attr} has a non numeric value for `length`",{attr:c})),b.message||this.notValid||"has an incorrect length")}},numericality:function(a,b){if(e.isDefined(a)){b=e.extend({},this.options,b);var c,d,f=[],g={greaterThan:function(a,b){return a>b},greaterThanOrEqualTo:function(a,b){return a>=b},equalTo:function(a,b){return a===b},lessThan:function(a,b){return b>a},lessThanOrEqualTo:function(a,b){return b>=a},divisibleBy:function(a,b){return a%b===0}};if(e.isString(a)&&b.strict){var h="^(0|[1-9]\\d*)";if(b.onlyInteger||(h+="(\\.\\d+)?"),h+="$",!new RegExp(h).test(a))return b.message||b.notValid||this.notValid||this.message||"must be a valid number"}if(b.noStrings!==!0&&e.isString(a)&&!e.isEmpty(a)&&(a=+a),!e.isNumber(a))return b.message||b.notValid||this.notValid||this.message||"is not a number";if(b.onlyInteger&&!e.isInteger(a))return b.message||b.notInteger||this.notInteger||this.message||"must be an integer";for(c in g)if(d=b[c],e.isNumber(d)&&!g[c](a,d)){var i="not"+e.capitalize(c),j=b[i]||this[i]||this.message||"must be %{type} %{count}";f.push(e.format(j,{count:d,type:e.prettify(c)}))}return b.odd&&a%2!==1&&f.push(b.notOdd||this.notOdd||this.message||"must be odd"),b.even&&a%2!==0&&f.push(b.notEven||this.notEven||this.message||"must be even"),f.length?b.message||f:void 0}},datetime:e.extend(function(a,b){if(!e.isFunction(this.parse)||!e.isFunction(this.format))throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");if(e.isDefined(a)){b=e.extend({},this.options,b);var c,d=[],f=b.earliest?this.parse(b.earliest,b):NaN,g=b.latest?this.parse(b.latest,b):NaN;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?(c=b.notValid||b.message||this.notValid||"must be a valid date",e.format(c,{value:arguments[0]})):(!isNaN(f)&&f>a&&(c=b.tooEarly||b.message||this.tooEarly||"must be no earlier than %{date}",c=e.format(c,{value:this.format(a,b),date:this.format(f,b)}),d.push(c)),!isNaN(g)&&a>g&&(c=b.tooLate||b.message||this.tooLate||"must be no later than %{date}",c=e.format(c,{date:this.format(g,b),value:this.format(a,b)}),d.push(c)),d.length?e.unique(d):void 0)}},{parse:null,format:null}),date:function(a,b){return b=e.extend({},b,{dateOnly:!0}),e.validators.datetime.call(e.validators.datetime,a,b)},format:function(a,b){(e.isString(b)||b instanceof RegExp)&&(b={pattern:b}),b=e.extend({},this.options,b);var c,d=b.message||this.message||"is invalid",f=b.pattern;return e.isDefined(a)?e.isString(a)?(e.isString(f)&&(f=new RegExp(b.pattern,b.flags)),c=f.exec(a),c&&c[0].length==a.length?void 0:d):d:void 0},inclusion:function(a,b){if(e.isDefined(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),!e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is not included in the list";return e.format(c,{value:a})}},exclusion:function(a,b){if(e.isDefined(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is restricted";return e.format(c,{value:a})}},email:e.extend(function(a,b){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid email";if(e.isDefined(a))return e.isString(a)&&this.PATTERN.exec(a)?void 0:c},{PATTERN:/^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i}),equality:function(a,b,c,d){if(e.isDefined(a)){e.isString(b)&&(b={attribute:b}),b=e.extend({},this.options,b);var f=b.message||this.message||"is not equal to %{attribute}";if(e.isEmpty(b.attribute)||!e.isString(b.attribute))throw new Error("The attribute must be a non empty string");var g=e.getDeepObjectValue(d,b.attribute),h=b.comparator||function(a,b){return a===b};return h(a,g,b,c,d)?void 0:e.format(f,{attribute:e.prettify(b.attribute)})}},url:function(a,b){if(e.isDefined(a)){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid url",d=b.schemes||this.schemes||["http","https"],f=b.allowLocal||this.allowLocal||!1;if(!e.isString(a))return c;var g="^(?:(?:"+d.join("|")+")://)(?:\\S+(?::\\S*)?@)?(?:",h="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";f?h+="?":g+="(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})",g+="(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*"+h+")(?::\\d{2,5})?(?:[/?#]\\S*)?$";var i=new RegExp(g,"i");return i.exec(a)?void 0:c}}},d.formatters={detailed:function(a){return a},flat:e.flattenErrorsToArray,grouped:function(a){var b;a=e.groupErrorsByAttribute(a);for(b in a)a[b]=e.flattenErrorsToArray(a[b]);return a}},d.exposeModule(d,this,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define:null); | ||
//# sourceMappingURL=validate.min.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1025397
53
6044