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
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) {
151 errors = v.pruneEmptyErrors(errors, options);
152 errors = v.expandMultipleErrors(errors, options);
153 errors = v.convertErrorMessages(errors, options);
155 switch (options.format || "grouped") {
157 // Do nothing more to the errors
161 errors = v.flattenErrorsToArray(errors);
165 errors = v.groupErrorsByAttribute(errors);
166 for (attr in errors) {
167 errors[attr] = v.flattenErrorsToArray(errors[attr]);
172 throw new Error(v.format("Unknown format %{format}", options));
175 return v.isEmpty(errors) ? undefined : errors;
178 // Runs the validations with support for promises.
179 // This function will return a promise that is settled when all the
180 // validation promises have been completed.
181 // It can be called even if no validations returned a promise.
182 async: function(attributes, constraints, options) {
183 options = v.extend({}, v.async.options, options);
185 var WrapErrors = options.wrapErrors || function(errors) {
189 // Removes unknown attributes
190 if (options.cleanAttributes !== false) {
191 attributes = v.cleanAttributes(attributes, constraints);
194 var results = v.runValidations(attributes, constraints, options);
196 return new v.Promise(function(resolve, reject) {
197 v.waitForResults(results).then(function() {
198 var errors = v.processValidationResults(results, options);
200 reject(new WrapErrors(errors, options, attributes, constraints));
210 single: function(value, constraints, options) {
211 options = v.extend({}, v.single.options, options, {
215 return v({single: value}, {single: constraints}, options);
218 // Returns a promise that is resolved when all promises in the results array
219 // are settled. The promise returned from this function is always resolved,
221 // This function modifies the input argument, it replaces the promises
222 // with the value returned from the promise.
223 waitForResults: function(results) {
224 // Create a sequence of all the results starting with a resolved promise.
225 return results.reduce(function(memo, result) {
226 // If this result isn't a promise skip it in the sequence.
227 if (!v.isPromise(result.error)) {
231 return memo.then(function() {
232 return result.error.then(
234 result.error = error || null;
237 if (error instanceof Error) {
240 v.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead.");
241 result.error = error;
245 }, new v.Promise(function(r) { r(); })); // A resolved promise
248 // If the given argument is a call: function the and: function return the value
249 // otherwise just return the value. Additional arguments will be passed as
250 // arguments to the function.
253 // result('foo') // 'foo'
254 // result(Math.max, 1, 2) // 2
256 result: function(value) {
257 var args = [].slice.call(arguments, 1);
258 if (typeof value === 'function') {
259 value = value.apply(null, args);
264 // Checks if the value is a number. This function does not consider NaN a
265 // number like many other `isNumber` functions do.
266 isNumber: function(value) {
267 return typeof value === 'number' && !isNaN(value);
270 // Returns false if the object is not a function
271 isFunction: function(value) {
272 return typeof value === 'function';
275 // A simple check to verify that the value is an integer. Uses `isNumber`
276 // and a simple modulo check.
277 isInteger: function(value) {
278 return v.isNumber(value) && value % 1 === 0;
281 // Checks if the value is a boolean
282 isBoolean: function(value) {
283 return typeof value === 'boolean';
286 // Uses the `Object` function to check if the given argument is an object.
287 isObject: function(obj) {
288 return obj === Object(obj);
291 // Simply checks if the object is an instance of a date
292 isDate: function(obj) {
293 return obj instanceof Date;
296 // Returns false if the object is `null` of `undefined`
297 isDefined: function(obj) {
298 return obj !== null && obj !== undefined;
301 // Checks if the given argument is a promise. Anything with a `then`
302 // function is considered a promise.
303 isPromise: function(p) {
304 return !!p && v.isFunction(p.then);
307 isJqueryElement: function(o) {
308 return o && v.isString(o.jquery);
311 isDomElement: function(o) {
316 if (!o.querySelectorAll || !o.querySelector) {
320 if (v.isObject(document) && o === document) {
324 // http://stackoverflow.com/a/384380/699304
325 /* istanbul ignore else */
326 if (typeof HTMLElement === "object") {
327 return o instanceof HTMLElement;
330 typeof o === "object" &&
333 typeof o.nodeName === "string";
337 isEmpty: function(value) {
340 // Null and undefined are empty
341 if (!v.isDefined(value)) {
345 // functions are non empty
346 if (v.isFunction(value)) {
350 // Whitespace only strings are empty
351 if (v.isString(value)) {
352 return v.EMPTY_STRING_REGEXP.test(value);
355 // For arrays we use the length property
356 if (v.isArray(value)) {
357 return value.length === 0;
360 // Dates have no attributes but aren't empty
361 if (v.isDate(value)) {
365 // If we find at least one property we consider it non empty
366 if (v.isObject(value)) {
367 for (attr in value) {
376 // Formats the specified strings with the given values like so:
378 // format("Foo: %{foo}", {foo: "bar"}) // "Foo bar"
380 // If you want to write %{...} without having it replaced simply
381 // prefix it with % like this `Foo: %%{foo}` and it will be returned
382 // as `"Foo: %{foo}"`
383 format: v.extend(function(str, vals) {
384 if (!v.isString(str)) {
387 return str.replace(v.format.FORMAT_REGEXP, function(m0, m1, m2) {
389 return "%{" + m2 + "}";
391 return String(vals[m2]);
395 // Finds %{key} style patterns in the given string
396 FORMAT_REGEXP: /(%?)%\{([^\}]+)\}/g
399 // "Prettifies" the given string.
400 // Prettifying means replacing [.\_-] with spaces as well as splitting
402 prettify: function(str) {
403 if (v.isNumber(str)) {
404 // If there are more than 2 decimals round it to two
405 if ((str * 100) % 1 === 0) {
408 return parseFloat(Math.round(str * 100) / 100).toFixed(2);
412 if (v.isArray(str)) {
413 return str.map(function(s) { return v.prettify(s); }).join(", ");
416 if (v.isObject(str)) {
417 return str.toString();
420 // Ensure the string is actually a string
424 // Splits keys separated by periods
425 .replace(/([^\s])\.([^\s])/g, '$1 $2')
426 // Removes backslashes
428 // Replaces - and - with space
429 .replace(/[_-]/g, ' ')
430 // Splits camel cased words
431 .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {
432 return "" + m1 + " " + m2.toLowerCase();
437 stringifyValue: function(value) {
438 return v.prettify(value);
441 isString: function(value) {
442 return typeof value === 'string';
445 isArray: function(value) {
446 return {}.toString.call(value) === '[object Array]';
449 // Checks if the object is a hash, which is equivalent to an object that
450 // is neither an array nor a function.
451 isHash: function(value) {
452 return v.isObject(value) && !v.isArray(value) && !v.isFunction(value);
455 contains: function(obj, value) {
456 if (!v.isDefined(obj)) {
459 if (v.isArray(obj)) {
460 return obj.indexOf(value) !== -1;
465 unique: function(array) {
466 if (!v.isArray(array)) {
469 return array.filter(function(el, index, array) {
470 return array.indexOf(el) == index;
474 forEachKeyInKeypath: function(object, keypath, callback) {
475 if (!v.isString(keypath)) {
483 for (i = 0; i < keypath.length; ++i) {
484 switch (keypath[i]) {
490 object = callback(object, key, false);
511 return callback(object, key, true);
514 getDeepObjectValue: function(obj, keypath) {
515 if (!v.isObject(obj)) {
519 return v.forEachKeyInKeypath(obj, keypath, function(obj, key) {
520 if (v.isObject(obj)) {
526 // This returns an object with all the values of the form.
527 // It uses the input name as key and the value as value
528 // So for example this:
529 // <input type="text" name="email" value="foo@bar.com" />
531 // {email: "foo@bar.com"}
532 collectFormValues: function(form, options) {
539 if (v.isJqueryElement(form)) {
547 options = options || {};
549 inputs = form.querySelectorAll("input[name], textarea[name]");
550 for (i = 0; i < inputs.length; ++i) {
551 input = inputs.item(i);
553 if (v.isDefined(input.getAttribute("data-ignored"))) {
557 value = v.sanitizeFormValue(input.value, options);
558 if (input.type === "number") {
559 value = value ? +value : null;
560 } else if (input.type === "checkbox") {
561 if (input.attributes.value) {
562 if (!input.checked) {
563 value = values[input.name] || null;
566 value = input.checked;
568 } else if (input.type === "radio") {
569 if (!input.checked) {
570 value = values[input.name] || null;
573 values[input.name] = value;
576 inputs = form.querySelectorAll("select[name]");
577 for (i = 0; i < inputs.length; ++i) {
578 input = inputs.item(i);
579 value = v.sanitizeFormValue(input.options[input.selectedIndex].value, options);
580 values[input.name] = value;
586 sanitizeFormValue: function(value, options) {
587 if (options.trim && v.isString(value)) {
588 value = value.trim();
591 if (options.nullify !== false && value === "") {
597 capitalize: function(str) {
598 if (!v.isString(str)) {
601 return str[0].toUpperCase() + str.slice(1);
604 // Remove all errors who's error attribute is empty (null or undefined)
605 pruneEmptyErrors: function(errors) {
606 return errors.filter(function(error) {
607 return !v.isEmpty(error.error);
612 // [{error: ["err1", "err2"], ...}]
614 // [{error: "err1", ...}, {error: "err2", ...}]
616 // All attributes in an error with multiple messages are duplicated
617 // when expanding the errors.
618 expandMultipleErrors: function(errors) {
620 errors.forEach(function(error) {
621 // Removes errors without a message
622 if (v.isArray(error.error)) {
623 error.error.forEach(function(msg) {
624 ret.push(v.extend({}, error, {error: msg}));
633 // Converts the error mesages by prepending the attribute name unless the
634 // message is prefixed by ^
635 convertErrorMessages: function(errors, options) {
636 options = options || {};
639 errors.forEach(function(errorInfo) {
640 var error = v.result(errorInfo.error,
644 errorInfo.attributes,
645 errorInfo.globalOptions);
647 if (!v.isString(error)) {
652 if (error[0] === '^') {
653 error = error.slice(1);
654 } else if (options.fullMessages !== false) {
655 error = v.capitalize(v.prettify(errorInfo.attribute)) + " " + error;
657 error = error.replace(/\\\^/g, "^");
658 error = v.format(error, {value: v.stringifyValue(errorInfo.value)});
659 ret.push(v.extend({}, errorInfo, {error: error}));
665 // [{attribute: "<attributeName>", ...}]
667 // {"<attributeName>": [{attribute: "<attributeName>", ...}]}
668 groupErrorsByAttribute: function(errors) {
670 errors.forEach(function(error) {
671 var list = ret[error.attribute];
675 ret[error.attribute] = [error];
682 // [{error: "<message 1>", ...}, {error: "<message 2>", ...}]
684 // ["<message 1>", "<message 2>"]
685 flattenErrorsToArray: function(errors) {
686 return errors.map(function(error) { return error.error; });
689 cleanAttributes: function(attributes, whitelist) {
690 function whitelistCreator(obj, key, last) {
691 if (v.isObject(obj[key])) {
694 return (obj[key] = last ? true : {});
697 function buildObjectWhitelist(whitelist) {
701 for (attr in whitelist) {
702 if (!whitelist[attr]) {
705 v.forEachKeyInKeypath(ow, attr, whitelistCreator);
710 function cleanRecursive(attributes, whitelist) {
711 if (!v.isObject(attributes)) {
715 var ret = v.extend({}, attributes)
719 for (attribute in attributes) {
720 w = whitelist[attribute];
723 ret[attribute] = cleanRecursive(ret[attribute], w);
725 delete ret[attribute];
731 if (!v.isObject(whitelist) || !v.isObject(attributes)) {
735 whitelist = buildObjectWhitelist(whitelist);
736 return cleanRecursive(attributes, whitelist);
739 exposeModule: function(validate, root, exports, module, define) {
741 if (module && module.exports) {
742 exports = module.exports = validate;
744 exports.validate = validate;
746 root.validate = validate;
747 if (validate.isFunction(define) && define.amd) {
748 define([], function () { return validate; });
753 warn: function(msg) {
754 if (typeof console !== "undefined" && console.warn) {
755 console.warn("[validate.js] " + msg);
759 error: function(msg) {
760 if (typeof console !== "undefined" && console.error) {
761 console.error("[validate.js] " + msg);
766 validate.validators = {
767 // Presence validates that the value isn't empty
768 presence: function(value, options) {
769 options = v.extend({}, this.options, options);
770 if (v.isEmpty(value)) {
771 return options.message || this.message || "can't be blank";
774 length: function(value, options, attribute) {
775 // Empty values are allowed
776 if (v.isEmpty(value)) {
780 options = v.extend({}, this.options, options);
783 , maximum = options.maximum
784 , minimum = options.minimum
785 , tokenizer = options.tokenizer || function(val) { return val; }
789 value = tokenizer(value);
790 var length = value.length;
791 if(!v.isNumber(length)) {
792 v.error(v.format("Attribute %{attr} has a non numeric value for `length`", {attr: attribute}));
793 return options.message || this.notValid || "has an incorrect length";
797 if (v.isNumber(is) && length !== is) {
798 err = options.wrongLength ||
800 "is the wrong length (should be %{count} characters)";
801 errors.push(v.format(err, {count: is}));
804 if (v.isNumber(minimum) && length < minimum) {
805 err = options.tooShort ||
807 "is too short (minimum is %{count} characters)";
808 errors.push(v.format(err, {count: minimum}));
811 if (v.isNumber(maximum) && length > maximum) {
812 err = options.tooLong ||
814 "is too long (maximum is %{count} characters)";
815 errors.push(v.format(err, {count: maximum}));
818 if (errors.length > 0) {
819 return options.message || errors;
822 numericality: function(value, options) {
823 // Empty values are fine
824 if (v.isEmpty(value)) {
828 options = v.extend({}, this.options, options);
834 greaterThan: function(v, c) { return v > c; },
835 greaterThanOrEqualTo: function(v, c) { return v >= c; },
836 equalTo: function(v, c) { return v === c; },
837 lessThan: function(v, c) { return v < c; },
838 lessThanOrEqualTo: function(v, c) { return v <= c; },
839 divisibleBy: function(v, c) { return v % c === 0; }
842 // Strict will check that it is a valid looking number
843 if (v.isString(value) && options.strict) {
844 var pattern = "^(0|[1-9]\\d*)";
845 if (!options.onlyInteger) {
846 pattern += "(\\.\\d+)?";
850 if (!(new RegExp(pattern).test(value))) {
851 return options.message || options.notValid || this.notValid || "must be a valid number";
855 // Coerce the value to a number unless we're being strict.
856 if (options.noStrings !== true && v.isString(value)) {
860 // If it's not a number we shouldn't continue since it will compare it.
861 if (!v.isNumber(value)) {
862 return options.message || options.notValid || this.notValid || "is not a number";
865 // Same logic as above, sort of. Don't bother with comparisons if this
867 if (options.onlyInteger && !v.isInteger(value)) {
868 return options.message || options.notInteger || this.notInteger || "must be an integer";
871 for (name in checks) {
872 count = options[name];
873 if (v.isNumber(count) && !checks[name](value, count)) {
874 // This picks the default message if specified
875 // For example the greaterThan check uses the message from
876 // this.notGreaterThan so we capitalize the name and prepend "not"
877 var key = "not" + v.capitalize(name);
878 var msg = options[key] || this[key] || "must be %{type} %{count}";
880 errors.push(v.format(msg, {
882 type: v.prettify(name)
887 if (options.odd && value % 2 !== 1) {
888 errors.push(options.notOdd || this.notOdd || "must be odd");
890 if (options.even && value % 2 !== 0) {
891 errors.push(options.notEven || this.notEven || "must be even");
895 return options.message || errors;
898 datetime: v.extend(function(value, options) {
899 if (!v.isFunction(this.parse) || !v.isFunction(this.format)) {
900 throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");
903 // Empty values are fine
904 if (v.isEmpty(value)) {
908 options = v.extend({}, this.options, options);
912 , earliest = options.earliest ? this.parse(options.earliest, options) : NaN
913 , latest = options.latest ? this.parse(options.latest, options) : NaN;
915 value = this.parse(value, options);
917 // 86400000 is the number of seconds in a day, this is used to remove
918 // the time from the date
919 if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
920 err = options.notValid ||
923 "must be a valid date";
924 return v.format(err, {value: arguments[0]});
927 if (!isNaN(earliest) && value < earliest) {
928 err = options.tooEarly ||
931 "must be no earlier than %{date}";
932 err = v.format(err, {
933 value: this.format(value, options),
934 date: this.format(earliest, options)
939 if (!isNaN(latest) && value > latest) {
940 err = options.tooLate ||
943 "must be no later than %{date}";
944 err = v.format(err, {
945 date: this.format(latest, options),
946 value: this.format(value, options)
952 return v.unique(errors);
958 date: function(value, options) {
959 options = v.extend({}, options, {dateOnly: true});
960 return v.validators.datetime.call(v.validators.datetime, value, options);
962 format: function(value, options) {
963 if (v.isString(options) || (options instanceof RegExp)) {
964 options = {pattern: options};
967 options = v.extend({}, this.options, options);
969 var message = options.message || this.message || "is invalid"
970 , pattern = options.pattern
973 // Empty values are allowed
974 if (v.isEmpty(value)) {
977 if (!v.isString(value)) {
981 if (v.isString(pattern)) {
982 pattern = new RegExp(options.pattern, options.flags);
984 match = pattern.exec(value);
985 if (!match || match[0].length != value.length) {
989 inclusion: function(value, options) {
990 // Empty values are fine
991 if (v.isEmpty(value)) {
994 if (v.isArray(options)) {
995 options = {within: options};
997 options = v.extend({}, this.options, options);
998 if (v.contains(options.within, value)) {
1001 var message = options.message ||
1003 "^%{value} is not included in the list";
1004 return v.format(message, {value: value});
1006 exclusion: function(value, options) {
1007 // Empty values are fine
1008 if (v.isEmpty(value)) {
1011 if (v.isArray(options)) {
1012 options = {within: options};
1014 options = v.extend({}, this.options, options);
1015 if (!v.contains(options.within, value)) {
1018 var message = options.message || this.message || "^%{value} is restricted";
1019 return v.format(message, {value: value});
1021 email: v.extend(function(value, options) {
1022 options = v.extend({}, this.options, options);
1023 var message = options.message || this.message || "is not a valid email";
1024 // Empty values are fine
1025 if (v.isEmpty(value)) {
1028 if (!v.isString(value)) {
1031 if (!this.PATTERN.exec(value)) {
1035 PATTERN: /^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i
1037 equality: function(value, options, attribute, attributes) {
1038 if (v.isEmpty(value)) {
1042 if (v.isString(options)) {
1043 options = {attribute: options};
1045 options = v.extend({}, this.options, options);
1046 var message = options.message ||
1048 "is not equal to %{attribute}";
1050 if (v.isEmpty(options.attribute) || !v.isString(options.attribute)) {
1051 throw new Error("The attribute must be a non empty string");
1054 var otherValue = v.getDeepObjectValue(attributes, options.attribute)
1055 , comparator = options.comparator || function(v1, v2) {
1059 if (!comparator(value, otherValue, options, attribute, attributes)) {
1060 return v.format(message, {attribute: v.prettify(options.attribute)});
1064 // A URL validator that is used to validate URLs with the ability to
1065 // restrict schemes and some domains.
1066 url: function(value, options) {
1067 if (v.isEmpty(value)) {
1071 options = v.extend({}, this.options, options);
1073 var message = options.message || this.message || "is not a valid url"
1074 , schemes = options.schemes || this.schemes || ['http', 'https']
1075 , allowLocal = options.allowLocal || this.allowLocal || false;
1077 if (!v.isString(value)) {
1081 // https://gist.github.com/dperini/729294
1085 "(?:(?:" + schemes.join("|") + "):\\/\\/)" +
1087 "(?:\\S+(?::\\S*)?@)?";
1091 var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
1093 // This ia a special case for the localhost hostname
1097 // private & local addresses
1099 "(?!10(?:\\.\\d{1,3}){3})" +
1100 "(?!127(?:\\.\\d{1,3}){3})" +
1101 "(?!169\\.254(?:\\.\\d{1,3}){2})" +
1102 "(?!192\\.168(?:\\.\\d{1,3}){2})" +
1104 "\\.(?:1[6-9]|2\\d|3[0-1])" +
1110 "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
1111 "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
1114 // reserved addresses
1116 "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
1117 "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
1118 "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
1127 var PATTERN = new RegExp(regex, 'i');
1128 if (!PATTERN.exec(value)) {
1134 validate.exposeModule(validate, this, exports, module, define);
1136 typeof exports !== 'undefined' ? /* istanbul ignore next */ exports : null,
1137 typeof module !== 'undefined' ? /* istanbul ignore next */ module : null,
1138 typeof define !== 'undefined' ? /* istanbul ignore next */ define : null);