Comparing version 0.4.0 to 0.4.1
@@ -206,1 +206,9 @@ /*jslint node: true */ | ||
exports.digits = function (message) { | ||
return exports.regexp(/^\d+$/, message || 'Numbers only.'); | ||
}; | ||
exports.integer = function (message) { | ||
return exports.regexp(/^-?\d+$/, message || 'Please enter an integer value.'); | ||
}; | ||
@@ -6,3 +6,3 @@ { | ||
"author": "Caolan McMahon", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"repository": { | ||
@@ -30,3 +30,3 @@ "type": "git", | ||
"testling": "~1.6.1", | ||
"covert": "~0.3.1" | ||
"covert": "~0.4.0" | ||
}, | ||
@@ -33,0 +33,0 @@ "licenses": [ |
@@ -190,2 +190,4 @@ # Forms <sup>[![Version Badge][9]][8]</sup> | ||
* alphanumeric | ||
* digits | ||
* integer | ||
@@ -192,0 +194,0 @@ ### Renderers |
@@ -364,1 +364,67 @@ /*jslint node: true */ | ||
}); | ||
test('integer', function (t) { | ||
var v = validators.integer(); | ||
t.test('valid integers', function(st) { | ||
var valids = ['1', '10', '-1', '-10', '-10']; | ||
st.plan(valids.length); | ||
valids.forEach(function (input) { | ||
v('form', { data: input }, function (err) { | ||
st.equal(err, undefined); | ||
}); | ||
}); | ||
st.end(); | ||
}); | ||
t.test('invalid integers', function(st) { | ||
var invalids = ['1.5', 'one', '1,5', 'FFFFF', '+10']; | ||
var msg = 'Please enter an integer value.'; | ||
st.plan(invalids.length); | ||
invalids.forEach(function (input) { | ||
v('form', { data: input }, function (err) { | ||
st.equal(err, msg); | ||
}); | ||
}); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); | ||
test('digits', function (t) { | ||
var v = validators.digits(); | ||
t.test('valid digits', function(st) { | ||
var valids = ['1', '10', '100']; | ||
st.plan(valids.length); | ||
valids.forEach(function (input) { | ||
v('form', { data: input }, function (err) { | ||
st.equal(err, undefined); | ||
}); | ||
}); | ||
st.end(); | ||
}); | ||
t.test('invalid digits', function(st) { | ||
var invalids = ['-1', '+10', 'one', '1.5']; | ||
var msg = 'Numbers only.'; | ||
st.plan(invalids.length); | ||
invalids.forEach(function (input) { | ||
v('form', { data: input }, function (err) { | ||
st.equal(err, msg); | ||
}); | ||
}); | ||
st.end(); | ||
}); | ||
t.end(); | ||
}); | ||
Sorry, the diff of this file is not supported yet
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
138013
25
3382
359