4 * (c) 2013-2016 Nicklas Ansman, 2013 Wrapp
5 * Validate.js may be freely distributed under the MIT license.
6 * For all details and documentation:
7 * http://validatejs.org/
10 (function(exports, module, define) {
13 // The main function that calls the validators specified by the constraints.
14 // The options are the following:
15 // - format (string) - An option that controls how the returned value is formatted
16 // * flat - Returns a flat array of just the error messages
17 // * grouped - Returns the messages grouped by attribute (default)
18 // * detailed - Returns an array of the raw validation data
19 // - fullMessages (boolean) - If `true` (default) the attribute name is prepended to the error.
21 // Please note that the options are also passed to each validator.
22 var validate = function(attributes, constraints, options) {
23 options = v.extend({}, v.options, options);
25 var results = v.runValidations(attributes, constraints, options)
29 for (attr in results) {
30 for (validator in results[attr]) {
31 if (v.isPromise(results[attr][validator])) {
32 throw new Error("Use validate.async if you want support for promises");
36 return validate.processValidationResults(results, options);
41 // Copies over attributes from one or more sources to a single destination.
42 // Very much similar to underscore's extend.
43 // The first argument is the target object and the remaining arguments will be
45 v.extend = function(obj) {
46 [].slice.call(arguments, 1).forEach(function(source) {
47 for (var attr in source) {
48 obj[attr] = source[attr];
55 // This is the version of the library as a semver.
56 // The toString function will allow it to be coerced into a string
61 metadata: "development",
62 toString: function() {
63 var version = v.format("%{major}.%{minor}.%{patch}", v.version);
64 if (!v.isEmpty(v.version.metadata)) {
65 version += "+" + v.version.metadata;
71 // Below is the dependencies that are used in validate.js
73 // The constructor of the Promise implementation.
74 // If you are using Q.js, RSVP or any other A+ compatible implementation
75 // override this attribute to be the constructor of that promise.
76 // Since jQuery promises aren't A+ compatible they won't work.
77 Promise: typeof Promise !== "undefined" ? Promise : /* istanbul ignore next */ null,
79 EMPTY_STRING_REGEXP: /^\s*$/,
81 // Runs the validators specified by the constraints object.
82 // Will return an array of the format:
83 // [{attribute: "<attribute name>", error: "<validation result>"}, ...]
84 runValidations: function(attributes, constraints, options) {
94 if (v.isDomElement(attributes) || v.isJqueryElement(attributes)) {
95 attributes = v.collectFormValues(attributes);
98 // Loops through each constraints, finds the correct validator and run it.
99 for (attr in constraints) {
100 value = v.getDeepObjectValue(attributes, attr);
101 // This allows the constraints for an attribute to be a function.
102 // The function will be called with the value, attribute name, the complete dict of
103 // attributes as well as the options and constraints passed in.
104 // This is useful when you want to have different
105 // validations depending on the attribute value.
106 validators = v.result(constraints[attr], value, attributes, attr, options, constraints);
108 for (validatorName in validators) {
109 validator = v.validators[validatorName];
112 error = v.format("Unknown validator %{name}", {name: validatorName});
113 throw new Error(error);
116 validatorOptions = validators[validatorName];
117 // This allows the options to be a function. The function will be
118 // called with the value, attribute name, the complete dict of
119 // attributes as well as the options and constraints passed in.
120 // This is useful when you want to have different
121 // validations depending on the attribute value.
122 validatorOptions = v.result(validatorOptions, value, attributes, attr, options, constraints);
123 if (!validatorOptions) {
129 validator: validatorName,
130 globalOptions: options,
131 attributes: attributes,
132 options: validatorOptions,
133 error: validator.call(validator,
146 // Takes the output from runValidations and converts it to the correct
148 processValidationResults: function(errors, options) {
149 errors = v.pruneEmptyErrors(errors, options);
150 errors = v.expandMultipleErrors(errors, options);
151 errors = v.convertErrorMessages(errors, options);
153 var format = options.format || "grouped";
155 if(typeof v.formatters[format] === 'function') {
156 errors = v.formatters[format](errors);
159 throw new Error(v.format("Unknown format %{format}", options));
162 return v.isEmpty(errors) ? undefined : errors;
165 // Runs the validations with support for promises.
166 // This function will return a promise that is settled when all the
167 // validation promises have been completed.
168 // It can be called even if no validations returned a promise.
169 async: function(attributes, constraints, options) {
170 options = v.extend({}, v.async.options, options);
172 var WrapErrors = options.wrapErrors || function(errors) {
176 // Removes unknown attributes
177 if (options.cleanAttributes !== false) {
178 attributes = v.cleanAttributes(attributes, constraints);
181 var results = v.runValidations(attributes, constraints, options);
183 return new v.Promise(function(resolve, reject) {
184 v.waitForResults(results).then(function() {
185 var errors = v.processValidationResults(results, options);
187 reject(new WrapErrors(errors, options, attributes, constraints));
197 single: function(value, constraints, options) {
198 options = v.extend({}, v.single.options, options, {
202 return v({single: value}, {single: constraints}, options);
205 // Returns a promise that is resolved when all promises in the results array
206 // are settled. The promise returned from this function is always resolved,
208 // This function modifies the input argument, it replaces the promises
209 // with the value returned from the promise.
210 waitForResults: function(results) {
211 // Create a sequence of all the results starting with a resolved promise.
212 return results.reduce(function(memo, result) {
213 // If this result isn't a promise skip it in the sequence.
214 if (!v.isPromise(result.error)) {
218 return memo.then(function() {
219 return result.error.then(function(error) {
220 result.error = error || null;
223 }, new v.Promise(function(r) { r(); })); // A resolved promise
226 // If the given argument is a call: function the and: function return the value
227 // otherwise just return the value. Additional arguments will be passed as
228 // arguments to the function.
231 // result('foo') // 'foo'
232 // result(Math.max, 1, 2) // 2
234 result: function(value) {
235 var args = [].slice.call(arguments, 1);
236 if (typeof value === 'function') {
237 value = value.apply(null, args);
242 // Checks if the value is a number. This function does not consider NaN a
243 // number like many other `isNumber` functions do.
244 isNumber: function(value) {
245 return typeof value === 'number' && !isNaN(value);
248 // Returns false if the object is not a function
249 isFunction: function(value) {
250 return typeof value === 'function';
253 // A simple check to verify that the value is an integer. Uses `isNumber`
254 // and a simple modulo check.
255 isInteger: function(value) {
256 return v.isNumber(value) && value % 1 === 0;
259 // Checks if the value is a boolean
260 isBoolean: function(value) {
261 return typeof value === 'boolean';
264 // Uses the `Object` function to check if the given argument is an object.
265 isObject: function(obj) {
266 return obj === Object(obj);
269 // Simply checks if the object is an instance of a date
270 isDate: function(obj) {
271 return obj instanceof Date;
274 // Returns false if the object is `null` of `undefined`
275 isDefined: function(obj) {
276 return obj !== null && obj !== undefined;
279 // Checks if the given argument is a promise. Anything with a `then`
280 // function is considered a promise.
281 isPromise: function(p) {
282 return !!p && v.isFunction(p.then);
285 isJqueryElement: function(o) {
286 return o && v.isString(o.jquery);
289 isDomElement: function(o) {
294 if (!o.querySelectorAll || !o.querySelector) {
298 if (v.isObject(document) && o === document) {
302 // http://stackoverflow.com/a/384380/699304
303 /* istanbul ignore else */
304 if (typeof HTMLElement === "object") {
305 return o instanceof HTMLElement;
308 typeof o === "object" &&
311 typeof o.nodeName === "string";
315 isEmpty: function(value) {
318 // Null and undefined are empty
319 if (!v.isDefined(value)) {
323 // functions are non empty
324 if (v.isFunction(value)) {
328 // Whitespace only strings are empty
329 if (v.isString(value)) {
330 return v.EMPTY_STRING_REGEXP.test(value);
333 // For arrays we use the length property
334 if (v.isArray(value)) {
335 return value.length === 0;
338 // Dates have no attributes but aren't empty
339 if (v.isDate(value)) {
343 // If we find at least one property we consider it non empty
344 if (v.isObject(value)) {
345 for (attr in value) {
354 // Formats the specified strings with the given values like so:
356 // format("Foo: %{foo}", {foo: "bar"}) // "Foo bar"
358 // If you want to write %{...} without having it replaced simply
359 // prefix it with % like this `Foo: %%{foo}` and it will be returned
360 // as `"Foo: %{foo}"`
361 format: v.extend(function(str, vals) {
362 if (!v.isString(str)) {
365 return str.replace(v.format.FORMAT_REGEXP, function(m0, m1, m2) {
367 return "%{" + m2 + "}";
369 return String(vals[m2]);
373 // Finds %{key} style patterns in the given string
374 FORMAT_REGEXP: /(%?)%\{([^\}]+)\}/g
377 // "Prettifies" the given string.
378 // Prettifying means replacing [.\_-] with spaces as well as splitting
380 prettify: function(str) {
381 if (v.isNumber(str)) {
382 // If there are more than 2 decimals round it to two
383 if ((str * 100) % 1 === 0) {
386 return parseFloat(Math.round(str * 100) / 100).toFixed(2);
390 if (v.isArray(str)) {
391 return str.map(function(s) { return v.prettify(s); }).join(", ");
394 if (v.isObject(str)) {
395 return str.toString();
398 // Ensure the string is actually a string
402 // Splits keys separated by periods
403 .replace(/([^\s])\.([^\s])/g, '$1 $2')
404 // Removes backslashes
406 // Replaces - and - with space
407 .replace(/[_-]/g, ' ')
408 // Splits camel cased words
409 .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {
410 return "" + m1 + " " + m2.toLowerCase();
415 stringifyValue: function(value) {
416 return v.prettify(value);
419 isString: function(value) {
420 return typeof value === 'string';
423 isArray: function(value) {
424 return {}.toString.call(value) === '[object Array]';
427 // Checks if the object is a hash, which is equivalent to an object that
428 // is neither an array nor a function.
429 isHash: function(value) {
430 return v.isObject(value) && !v.isArray(value) && !v.isFunction(value);
433 contains: function(obj, value) {
434 if (!v.isDefined(obj)) {
437 if (v.isArray(obj)) {
438 return obj.indexOf(value) !== -1;
443 unique: function(array) {
444 if (!v.isArray(array)) {
447 return array.filter(function(el, index, array) {
448 return array.indexOf(el) == index;
452 forEachKeyInKeypath: function(object, keypath, callback) {
453 if (!v.isString(keypath)) {
461 for (i = 0; i < keypath.length; ++i) {
462 switch (keypath[i]) {
468 object = callback(object, key, false);
489 return callback(object, key, true);
492 getDeepObjectValue: function(obj, keypath) {
493 if (!v.isObject(obj)) {
497 return v.forEachKeyInKeypath(obj, keypath, function(obj, key) {
498 if (v.isObject(obj)) {
504 // This returns an object with all the values of the form.
505 // It uses the input name as key and the value as value
506 // So for example this:
507 // <input type="text" name="email" value="foo@bar.com" />
509 // {email: "foo@bar.com"}
510 collectFormValues: function(form, options) {
519 if (v.isJqueryElement(form)) {
527 options = options || {};
529 inputs = form.querySelectorAll("input[name], textarea[name]");
530 for (i = 0; i < inputs.length; ++i) {
531 input = inputs.item(i);
533 if (v.isDefined(input.getAttribute("data-ignored"))) {
537 value = v.sanitizeFormValue(input.value, options);
538 if (input.type === "number") {
539 value = value ? +value : null;
540 } else if (input.type === "checkbox") {
541 if (input.attributes.value) {
542 if (!input.checked) {
543 value = values[input.name] || null;
546 value = input.checked;
548 } else if (input.type === "radio") {
549 if (!input.checked) {
550 value = values[input.name] || null;
553 values[input.name] = value;
556 inputs = form.querySelectorAll("select[name]");
557 for (i = 0; i < inputs.length; ++i) {
558 input = inputs.item(i);
559 if (input.multiple) {
562 for (j in input.options) {
563 option = input.options[j];
564 if (option.selected) {
565 value.push(v.sanitizeFormValue(option.value, options));
569 value = v.sanitizeFormValue(input.options[input.selectedIndex].value, options);
571 values[input.name] = value;
577 sanitizeFormValue: function(value, options) {
578 if (options.trim && v.isString(value)) {
579 value = value.trim();
582 if (options.nullify !== false && value === "") {
588 capitalize: function(str) {
589 if (!v.isString(str)) {
592 return str[0].toUpperCase() + str.slice(1);
595 // Remove all errors who's error attribute is empty (null or undefined)
596 pruneEmptyErrors: function(errors) {
597 return errors.filter(function(error) {
598 return !v.isEmpty(error.error);
603 // [{error: ["err1", "err2"], ...}]
605 // [{error: "err1", ...}, {error: "err2", ...}]
607 // All attributes in an error with multiple messages are duplicated
608 // when expanding the errors.
609 expandMultipleErrors: function(errors) {
611 errors.forEach(function(error) {
612 // Removes errors without a message
613 if (v.isArray(error.error)) {
614 error.error.forEach(function(msg) {
615 ret.push(v.extend({}, error, {error: msg}));
624 // Converts the error mesages by prepending the attribute name unless the
625 // message is prefixed by ^
626 convertErrorMessages: function(errors, options) {
627 options = options || {};
630 errors.forEach(function(errorInfo) {
631 var error = v.result(errorInfo.error,
635 errorInfo.attributes,
636 errorInfo.globalOptions);
638 if (!v.isString(error)) {
643 if (error[0] === '^') {
644 error = error.slice(1);
645 } else if (options.fullMessages !== false) {
646 error = v.capitalize(v.prettify(errorInfo.attribute)) + " " + error;
648 error = error.replace(/\\\^/g, "^");
649 error = v.format(error, {value: v.stringifyValue(errorInfo.value)});
650 ret.push(v.extend({}, errorInfo, {error: error}));
656 // [{attribute: "<attributeName>", ...}]
658 // {"<attributeName>": [{attribute: "<attributeName>", ...}]}
659 groupErrorsByAttribute: function(errors) {
661 errors.forEach(function(error) {
662 var list = ret[error.attribute];
666 ret[error.attribute] = [error];
673 // [{error: "<message 1>", ...}, {error: "<message 2>", ...}]
675 // ["<message 1>", "<message 2>"]
676 flattenErrorsToArray: function(errors) {
677 return errors.map(function(error) { return error.error; });
680 cleanAttributes: function(attributes, whitelist) {
681 function whitelistCreator(obj, key, last) {
682 if (v.isObject(obj[key])) {
685 return (obj[key] = last ? true : {});
688 function buildObjectWhitelist(whitelist) {
692 for (attr in whitelist) {
693 if (!whitelist[attr]) {
696 v.forEachKeyInKeypath(ow, attr, whitelistCreator);
701 function cleanRecursive(attributes, whitelist) {
702 if (!v.isObject(attributes)) {
706 var ret = v.extend({}, attributes)
710 for (attribute in attributes) {
711 w = whitelist[attribute];
714 ret[attribute] = cleanRecursive(ret[attribute], w);
716 delete ret[attribute];
722 if (!v.isObject(whitelist) || !v.isObject(attributes)) {
726 whitelist = buildObjectWhitelist(whitelist);
727 return cleanRecursive(attributes, whitelist);
730 exposeModule: function(validate, root, exports, module, define) {
732 if (module && module.exports) {
733 exports = module.exports = validate;
735 exports.validate = validate;
737 root.validate = validate;
738 if (validate.isFunction(define) && define.amd) {
739 define([], function () { return validate; });
744 warn: function(msg) {
745 if (typeof console !== "undefined" && console.warn) {
746 console.warn("[validate.js] " + msg);
750 error: function(msg) {
751 if (typeof console !== "undefined" && console.error) {
752 console.error("[validate.js] " + msg);
757 validate.validators = {
758 // Presence validates that the value isn't empty
759 presence: function(value, options) {
760 options = v.extend({}, this.options, options);
761 if (v.isEmpty(value)) {
762 return options.message || this.message || "can't be blank";
765 length: function(value, options, attribute) {
766 // Empty values are allowed
767 if (v.isEmpty(value)) {
771 options = v.extend({}, this.options, options);
774 , maximum = options.maximum
775 , minimum = options.minimum
776 , tokenizer = options.tokenizer || function(val) { return val; }
780 value = tokenizer(value);
781 var length = value.length;
782 if(!v.isNumber(length)) {
783 v.error(v.format("Attribute %{attr} has a non numeric value for `length`", {attr: attribute}));
784 return options.message || this.notValid || "has an incorrect length";
788 if (v.isNumber(is) && length !== is) {
789 err = options.wrongLength ||
791 "is the wrong length (should be %{count} characters)";
792 errors.push(v.format(err, {count: is}));
795 if (v.isNumber(minimum) && length < minimum) {
796 err = options.tooShort ||
798 "is too short (minimum is %{count} characters)";
799 errors.push(v.format(err, {count: minimum}));
802 if (v.isNumber(maximum) && length > maximum) {
803 err = options.tooLong ||
805 "is too long (maximum is %{count} characters)";
806 errors.push(v.format(err, {count: maximum}));
809 if (errors.length > 0) {
810 return options.message || errors;
813 numericality: function(value, options) {
814 // Empty values are fine
815 if (v.isEmpty(value)) {
819 options = v.extend({}, this.options, options);
825 greaterThan: function(v, c) { return v > c; },
826 greaterThanOrEqualTo: function(v, c) { return v >= c; },
827 equalTo: function(v, c) { return v === c; },
828 lessThan: function(v, c) { return v < c; },
829 lessThanOrEqualTo: function(v, c) { return v <= c; },
830 divisibleBy: function(v, c) { return v % c === 0; }
833 // Strict will check that it is a valid looking number
834 if (v.isString(value) && options.strict) {
835 var pattern = "^(0|[1-9]\\d*)";
836 if (!options.onlyInteger) {
837 pattern += "(\\.\\d+)?";
841 if (!(new RegExp(pattern).test(value))) {
842 return options.message || options.notValid || this.notValid || "must be a valid number";
846 // Coerce the value to a number unless we're being strict.
847 if (options.noStrings !== true && v.isString(value)) {
851 // If it's not a number we shouldn't continue since it will compare it.
852 if (!v.isNumber(value)) {
853 return options.message || options.notValid || this.notValid || "is not a number";
856 // Same logic as above, sort of. Don't bother with comparisons if this
858 if (options.onlyInteger && !v.isInteger(value)) {
859 return options.message || options.notInteger || this.notInteger || "must be an integer";
862 for (name in checks) {
863 count = options[name];
864 if (v.isNumber(count) && !checks[name](value, count)) {
865 // This picks the default message if specified
866 // For example the greaterThan check uses the message from
867 // this.notGreaterThan so we capitalize the name and prepend "not"
868 var key = "not" + v.capitalize(name);
869 var msg = options[key] || this[key] || "must be %{type} %{count}";
871 errors.push(v.format(msg, {
873 type: v.prettify(name)
878 if (options.odd && value % 2 !== 1) {
879 errors.push(options.notOdd || this.notOdd || "must be odd");
881 if (options.even && value % 2 !== 0) {
882 errors.push(options.notEven || this.notEven || "must be even");
886 return options.message || errors;
889 datetime: v.extend(function(value, options) {
890 if (!v.isFunction(this.parse) || !v.isFunction(this.format)) {
891 throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");
894 // Empty values are fine
895 if (v.isEmpty(value)) {
899 options = v.extend({}, this.options, options);
903 , earliest = options.earliest ? this.parse(options.earliest, options) : NaN
904 , latest = options.latest ? this.parse(options.latest, options) : NaN;
906 value = this.parse(value, options);
908 // 86400000 is the number of seconds in a day, this is used to remove
909 // the time from the date
910 if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
911 err = options.notValid ||
914 "must be a valid date";
915 return v.format(err, {value: arguments[0]});
918 if (!isNaN(earliest) && value < earliest) {
919 err = options.tooEarly ||
922 "must be no earlier than %{date}";
923 err = v.format(err, {
924 value: this.format(value, options),
925 date: this.format(earliest, options)
930 if (!isNaN(latest) && value > latest) {
931 err = options.tooLate ||
934 "must be no later than %{date}";
935 err = v.format(err, {
936 date: this.format(latest, options),
937 value: this.format(value, options)
943 return v.unique(errors);
949 date: function(value, options) {
950 options = v.extend({}, options, {dateOnly: true});
951 return v.validators.datetime.call(v.validators.datetime, value, options);
953 format: function(value, options) {
954 if (v.isString(options) || (options instanceof RegExp)) {
955 options = {pattern: options};
958 options = v.extend({}, this.options, options);
960 var message = options.message || this.message || "is invalid"
961 , pattern = options.pattern
964 // Empty values are allowed
965 if (v.isEmpty(value)) {
968 if (!v.isString(value)) {
972 if (v.isString(pattern)) {
973 pattern = new RegExp(options.pattern, options.flags);
975 match = pattern.exec(value);
976 if (!match || match[0].length != value.length) {
980 inclusion: function(value, options) {
981 // Empty values are fine
982 if (v.isEmpty(value)) {
985 if (v.isArray(options)) {
986 options = {within: options};
988 options = v.extend({}, this.options, options);
989 if (v.contains(options.within, value)) {
992 var message = options.message ||
994 "^%{value} is not included in the list";
995 return v.format(message, {value: value});
997 exclusion: function(value, options) {
998 // Empty values are fine
999 if (v.isEmpty(value)) {
1002 if (v.isArray(options)) {
1003 options = {within: options};
1005 options = v.extend({}, this.options, options);
1006 if (!v.contains(options.within, value)) {
1009 var message = options.message || this.message || "^%{value} is restricted";
1010 return v.format(message, {value: value});
1012 email: v.extend(function(value, options) {
1013 options = v.extend({}, this.options, options);
1014 var message = options.message || this.message || "is not a valid email";
1015 // Empty values are fine
1016 if (v.isEmpty(value)) {
1019 if (!v.isString(value)) {
1022 if (!this.PATTERN.exec(value)) {
1026 PATTERN: /^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i
1028 equality: function(value, options, attribute, attributes) {
1029 if (v.isEmpty(value)) {
1033 if (v.isString(options)) {
1034 options = {attribute: options};
1036 options = v.extend({}, this.options, options);
1037 var message = options.message ||
1039 "is not equal to %{attribute}";
1041 if (v.isEmpty(options.attribute) || !v.isString(options.attribute)) {
1042 throw new Error("The attribute must be a non empty string");
1045 var otherValue = v.getDeepObjectValue(attributes, options.attribute)
1046 , comparator = options.comparator || function(v1, v2) {
1050 if (!comparator(value, otherValue, options, attribute, attributes)) {
1051 return v.format(message, {attribute: v.prettify(options.attribute)});
1055 // A URL validator that is used to validate URLs with the ability to
1056 // restrict schemes and some domains.
1057 url: function(value, options) {
1058 if (v.isEmpty(value)) {
1062 options = v.extend({}, this.options, options);
1064 var message = options.message || this.message || "is not a valid url"
1065 , schemes = options.schemes || this.schemes || ['http', 'https']
1066 , allowLocal = options.allowLocal || this.allowLocal || false;
1068 if (!v.isString(value)) {
1072 // https://gist.github.com/dperini/729294
1076 "(?:(?:" + schemes.join("|") + "):\\/\\/)" +
1078 "(?:\\S+(?::\\S*)?@)?";
1082 var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
1084 // This ia a special case for the localhost hostname
1088 // private & local addresses
1090 "(?!10(?:\\.\\d{1,3}){3})" +
1091 "(?!127(?:\\.\\d{1,3}){3})" +
1092 "(?!169\\.254(?:\\.\\d{1,3}){2})" +
1093 "(?!192\\.168(?:\\.\\d{1,3}){2})" +
1095 "\\.(?:1[6-9]|2\\d|3[0-1])" +
1101 "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
1102 "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
1105 // reserved addresses
1107 "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
1108 "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
1109 "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
1118 var PATTERN = new RegExp(regex, 'i');
1119 if (!PATTERN.exec(value)) {
1125 validate.formatters = {
1126 detailed: function(errors) {return errors;},
1127 flat: v.flattenErrorsToArray,
1128 grouped: function(errors) {
1131 errors = v.groupErrorsByAttribute(errors);
1132 for (attr in errors) {
1133 errors[attr] = v.flattenErrorsToArray(errors[attr]);
1139 validate.exposeModule(validate, this, exports, module, define);
1141 typeof exports !== 'undefined' ? /* istanbul ignore next */ exports : null,
1142 typeof module !== 'undefined' ? /* istanbul ignore next */ module : null,
1143 typeof define !== 'undefined' ? /* istanbul ignore next */ define : null);