validator
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -12,3 +12,3 @@ var net = require('net'); | ||
this.msg = fail_msg; | ||
this._errors = []; | ||
this._errors = this._errors || []; | ||
return this; | ||
@@ -134,2 +134,9 @@ } | ||
Validator.prototype.isDivisibleBy = function(n) { | ||
if (parseFloat(this.str) % n) { | ||
return this.error(this.msg || 'Not divisible by ' + n); | ||
} | ||
return this; | ||
} | ||
Validator.prototype.notNull = function() { | ||
@@ -278,2 +285,3 @@ if (this.str === '') { | ||
var number = parseFloat(this.str); | ||
if (!isNaN(number) && number < val) { | ||
@@ -287,2 +295,3 @@ return this.error(this.msg || 'Invalid number'); | ||
var number = parseFloat(this.str); | ||
if (!isNaN(number) && number > val) { | ||
@@ -289,0 +298,0 @@ return this.error(this.msg || 'Invalid number'); |
{ "name" : "validator", | ||
"description" : "Data validation, filtering and sanitization for node.js", | ||
"version" : "0.3.5", | ||
"version" : "0.3.6", | ||
"homepage" : "http://github.com/chriso/node-validator", | ||
@@ -5,0 +5,0 @@ "keywords" : ["validator", "validation", "assert", "params", "sanitization", "xss", "entities", "sanitize", "sanitisation", "input"], |
@@ -180,2 +180,9 @@ **node-validator is a library of string validation, filtering and sanitization methods.** | ||
} | ||
var validator = new Validator(); | ||
validator.check('abc').isEmail(); | ||
validator.check('hello').len(10,30); | ||
var errors = validator.getErrors(); // ['Invalid email', 'String is too small'] | ||
``` | ||
@@ -182,0 +189,0 @@ |
@@ -482,3 +482,16 @@ var node_validator = require('../lib'), | ||
}, | ||
'test #isDate()': function() { | ||
assert.ok(Validator.check('2011-08-04').isDate()); | ||
assert.ok(Validator.check('04. 08. 2011.').isDate()); | ||
assert.ok(Validator.check('08/04/2011').isDate()); | ||
assert.ok(Validator.check('2011.08.04').isDate()); | ||
assert.ok(Validator.check('4. 8. 2011. GMT').isDate()); | ||
assert.ok(Validator.check('2011-08-04 12:00').isDate()); | ||
assert.throws(Validator.check('foo').isDate); | ||
assert.throws(Validator.check('2011-foo-04').isDate); | ||
assert.throws(Validator.check('GMT').isDate); | ||
}, | ||
'test #min()': function() { | ||
@@ -496,3 +509,2 @@ assert.ok(Validator.check('4').min(2)); | ||
}); | ||
}, | ||
@@ -580,3 +592,16 @@ | ||
}); | ||
}, | ||
'test #isDivisibleBy()': function() { | ||
assert.ok(Validator.check('10').isDivisibleBy(2)); | ||
assert.ok(Validator.check('6').isDivisibleBy(3)); | ||
assert.throws(function() { | ||
Validator.check('5').isDivisibleBy(2); | ||
}); | ||
assert.throws(function() { | ||
Validator.check('6.7').isDivisibleBy(3); | ||
}); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107842
2294
221