diff --git a/docs/validate.html b/docs/validate.html
index 96360c0..452b8ba 100644
--- a/docs/validate.html
+++ b/docs/validate.html
@@ -69,9 +69,7 @@
var validate = function(attributes, constraints, options) {
options = v.extend({}, v.options, options);
- var results = v.runValidations(attributes, constraints, options)
- , attr
- , validator;
+ var results = v.runValidations(attributes, constraints, options);
if (results.some(function(r) { return v.isPromise(r.error); })) {
throw new Error("Use validate.async if you want support for promises");
@@ -123,11 +121,11 @@ validate.js
version: {
- major: 0,
- minor: 12,
- patch: 0,
- metadata: null,
- toString: function() {
+ major: 0,
+ minor: 12,
+ patch: 0,
+ metadata: "development",
+ toString: function() {
var version = v.format("%{major}.%{minor}.%{patch}", v.version);
if (!v.isEmpty(v.version.metadata)) {
version += "+" + v.version.metadata;
@@ -167,7 +165,7 @@ validate.js
Promise: typeof Promise !== "undefined" ? Promise : null,
- EMPTY_STRING_REGEXP: /^\s*$/,
+ EMPTY_STRING_REGEXP: /^\s*$/,
@@ -237,7 +235,7 @@
validate.js
validator = v.validators[validatorName];
if (!validator) {
- error = v.format(
"Unknown validator %{name}", {name: validatorName});
+ error = v.format(
"Unknown validator %{name}", {
name: validatorName});
throw new Error(error);
}
@@ -265,13 +263,13 @@
validate.js
continue;
}
results.push({
- attribute: attr,
- value: value,
- validator: validatorName,
- globalOptions: options,
- attributes: attributes,
- options: validatorOptions,
- error: validator.call(validator,
+
attribute: attr,
+
value: value,
+
validator: validatorName,
+
globalOptions: options,
+
attributes: attributes,
+
options: validatorOptions,
+
error: validator.call(validator,
value,
validatorOptions,
attr,
@@ -370,12 +368,12 @@
validate.js
});
},
- single:
function(value, constraints, options) {
+
single:
function(value, constraints, options) {
options = v.extend({}, v.single.options, options, {
- format:
"flat",
- fullMessages:
false
+
format:
"flat",
+
fullMessages:
false
});
-
return v({single: value}, {single: constraints}, options);
+
return v({
single: value}, {
single: constraints}, options);
},
@@ -602,11 +600,11 @@ if (v.isArray(error.error)) {
error.error.forEach(function(msg) {
- ret.push(v.extend({}, error, {error: msg}));
+ ret.push(v.extend({}, error, {error: msg}));
});
} else {
ret.push(error);
@@ -1242,9 +1240,9 @@ validate.js
}
error = error.replace(/\\\^/g, "^");
error = v.format(error, {
- value: v.stringifyValue(errorInfo.value, options)
+ value: v.stringifyValue(errorInfo.value, options)
});
- ret.push(v.extend({}, errorInfo, {error: error}));
+ ret.push(v.extend({}, errorInfo, {error: error}));
});
return ret;
},
@@ -1302,7 +1300,7 @@ if (v.isNumber(is) && length !== is) {
- err = options.wrongLength ||
- this.wrongLength ||
- "is the wrong length (should be %{count} characters)";
- errors.push(v.format(err, {count: is}));
+ err = v.lang("length.wrongLength", options.wrongLength || options.message || this.wrongLength || this.message);
+ errors.push(v.format(err, {count: is}));
}
if (v.isNumber(minimum) && length < minimum) {
- err = options.tooShort ||
- this.tooShort ||
- "is too short (minimum is %{count} characters)";
- errors.push(v.format(err, {count: minimum}));
+ err = v.lang("length.tooShort", options.tooShort || options.message || this.tooShort || this.message);
+ errors.push(v.format(err, {count: minimum}));
}
if (v.isNumber(maximum) && length > maximum) {
- err = options.tooLong ||
- this.tooLong ||
- "is too long (maximum is %{count} characters)";
- errors.push(v.format(err, {count: maximum}));
+ err = v.lang("length.tooLong", options.tooLong || options.message || this.tooLong || this.message);
+ errors.push(v.format(err, {count: maximum}));
}
if (errors.length > 0) {
- return options.message || errors;
+ return v.lang("length.message", options.message || this.message) || errors;
}
},
- numericality: function(value, options, attribute, attributes, globalOptions) {
+ if (!v.isNumber(value)) {
- return options.message ||
- options.notValid ||
- this.notValid ||
- this.message ||
- "is not a number";
+ return v.lang(
+ "numericality.notValid",
+ options.notValid || options.message || this.notValid || this.message
+ );
}
@@ -1591,11 +1579,10 @@ if (options.onlyInteger && !v.isInteger(value)) {
- return options.message ||
- options.notInteger ||
- this.notInteger ||
- this.message ||
- "must be an integer";
+ return v.lang(
+ "numericality.notInteger",
+ options.notInteger || options.message || this.notInteger || this.message
+ );
}
for (name in checks) {
@@ -1618,36 +1605,34 @@ validate.js
var key = "not" + v.capitalize(name);
- var msg = options[key] ||
- this[key] ||
- this.message ||
- "must be %{type} %{count}";
+ var msg = v.lang(
+ "numericality." + key,
+ options[key] || options.message || this[key] || this.message
+ ) ||
+ v.lang(
+ 'numericality.check',
+ options.message || this.message
+ );
errors.push(v.format(msg, {
- count: count,
- type: prettify(name)
+ count: count,
+ type: prettify(name)
}));
}
}
if (options.odd && value % 2 !== 1) {
- errors.push(options.notOdd ||
- this.notOdd ||
- this.message ||
- "must be odd");
+ errors.push(v.lang("numericality.notOdd", options.notOdd || options.message || this.notOdd || this.message));
}
if (options.even && value % 2 !== 0) {
- errors.push(options.notEven ||
- this.notEven ||
- this.message ||
- "must be even");
+ errors.push(v.lang("numericality.notEven", options.notEven || options.message || this.notEven || this.message));
}
if (errors.length) {
- return options.message || errors;
+ return v.lang("numericality.message", options.message) || errors;
}
},
- datetime: v.extend(function(value, options) {
+ datetime: v.extend(function(value, options) {
if (!v.isFunction(this.parse) || !v.isFunction(this.format)) {
throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");
}
@@ -1693,33 +1678,24 @@
validate.js
if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
- err = options.notValid ||
- options.message ||
- this.notValid ||
- "must be a valid date";
- return v.format(err, {value: arguments[0]});
+ err = v.lang("datetime.notValid", options.notValid || options.message || this.notValid || this.message);
+ return v.format(err, {value: arguments[0]});
}
if (!isNaN(earliest) && value < earliest) {
- err = options.tooEarly ||
- options.message ||
- this.tooEarly ||
- "must be no earlier than %{date}";
+ err = v.lang("datetime.tooEarly", options.tooEarly || options.message || this.tooEarly || this.message);
err = v.format(err, {
- value: this.format(value, options),
- date: this.format(earliest, options)
+ value: this.format(value, options),
+ date: this.format(earliest, options)
});
errors.push(err);
}
if (!isNaN(latest) && value > latest) {
- err = options.tooLate ||
- options.message ||
- this.tooLate ||
- "must be no later than %{date}";
+ err = v.lang("datetime.tooLate", options.tooLate || options.message || this.tooLate || this.message);
err = v.format(err, {
- date: this.format(latest, options),
- value: this.format(value, options)
+ date: this.format(latest, options),
+ value: this.format(value, options)
});
errors.push(err);
}
@@ -1728,21 +1704,21 @@ validate.js
return v.unique(errors);
}
}, {
- parse: null,
- format: null
+ parse: null,
+ format: null
}),
- date: function(value, options) {
- options = v.extend({}, options, {dateOnly: true});
+ date: function(value, options) {
+ options = v.extend({}, options, {dateOnly: true});
return v.validators.datetime.call(v.validators.datetime, value, options);
},
- format: function(value, options) {
+ format: function(value, options) {
if (v.isString(options) || (options instanceof RegExp)) {
- options = {pattern: options};
+ options = {pattern: options};
}
options = v.extend({}, this.options, options);
- var message = options.message || this.message || "is invalid"
+ var message = v.lang("format.notValid", options.message || this.message)
, pattern = options.pattern
, match;
@@ -1774,7 +1750,7 @@