hmpo-form-controller
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,3 +0,2 @@ | ||
var moment = require('moment'), | ||
_ = require('underscore'); | ||
var moment = require('moment'); | ||
@@ -24,3 +23,3 @@ // validator methods should return false (or falsy value) for *invalid* input | ||
email: function email(value) { | ||
return Validators.regex(value, /^[a-z0-9\._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,6}$/i); | ||
return value === '' || Validators.regex(value, /^[a-z0-9\._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,6}$/i); | ||
}, | ||
@@ -30,11 +29,11 @@ | ||
length = length || 0; | ||
return Validators.string(value) && value.length >= length; | ||
return Validators.string(value) && (value === '' || value.length >= length); | ||
}, | ||
maxlength: function maxlength(value, length) { | ||
return Validators.string(value) && value.length <= length; | ||
return Validators.string(value) && (value === '' || value.length <= length); | ||
}, | ||
exactlength: function exactlength(value, length) { | ||
return Validators.string(value) && value.length === length; | ||
return Validators.string(value) && (value === '' || value.length === length); | ||
}, | ||
@@ -47,3 +46,3 @@ | ||
numeric: function numeric(value) { | ||
return Validators.regex(value, /^\d+$/); | ||
return Validators.regex(value, /^\d*$/); | ||
}, | ||
@@ -53,15 +52,15 @@ | ||
var values = [].slice.call(arguments, 1); | ||
return values.length && _.any(values, function (c) { return value === c; }); | ||
return values.length && (value === '' || values.indexOf(value) > -1); | ||
}, | ||
phonenumber: function phonenumber(value) { | ||
return Validators.regex(value, /^\(?\+?[\d()-]{0,15}$/); | ||
return value === '' || Validators.regex(value, /^\(?\+?[\d()-]{0,15}$/); | ||
}, | ||
ukmobilephone: function ukmobilephone(value) { | ||
return Validators.regex(value, /^(07)\d{9}$/); | ||
return value === '' || Validators.regex(value, /^(07)\d{9}$/); | ||
}, | ||
date: function date(value) { | ||
return Validators.regex(value, /\d{4}\-\d{2}\-\d{2}/) && moment(value, dateFormat).isValid(); | ||
return value === '' || Validators.regex(value, /\d{4}\-\d{2}\-\d{2}/) && moment(value, dateFormat).isValid(); | ||
}, | ||
@@ -78,3 +77,3 @@ | ||
} | ||
return Validators.date(value) && date.isBefore(moment()); | ||
return value === '' || Validators.date(value) && date.isBefore(moment()); | ||
}, | ||
@@ -97,9 +96,9 @@ | ||
} | ||
return Validators.date(value) && test.isAfter(comparator); | ||
return value === '' || Validators.date(value) && test.isAfter(comparator); | ||
}, | ||
postcode: function postcode(value) { | ||
return Validators.regex(value, /^([GIR] ?0[A]{2})|((([A-Z][0-9]{1,2})|(([A-Z][A-HJ-Y][0-9]{1,2})|(([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9]?[A-Z])))) ?[0-9][A-Z]{2})$/i); | ||
return value === '' || Validators.regex(value, /^([GIR] ?0[A]{2})|((([A-Z][0-9]{1,2})|(([A-Z][A-HJ-Y][0-9]{1,2})|(([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9]?[A-Z])))) ?[0-9][A-Z]{2})$/i); | ||
} | ||
}; |
{ | ||
"name": "hmpo-form-controller", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -53,2 +53,8 @@ # passports-form-controller | ||
These methods are synchronous and take only the request and response obejct as arguments. | ||
These methods are synchronous and take only the request and response obejct as arguments. | ||
### Validators | ||
The library [supports a number of validators](https://github.com/UKHomeOffice/passports-form-controller/blob/master/lib/validation/validators.js). | ||
By default the application of a validator is optional on empty strings. If you need to ensure a field is validated as being 9 characters long and exists then you need to use both an `exactlength` and a `required` validator. |
@@ -79,2 +79,3 @@ var Validators = require('../../').validators; | ||
var inputs = [ | ||
'', | ||
't@i.co', | ||
@@ -101,3 +102,2 @@ 'test@example.com', | ||
[100, 1], | ||
['', 1], | ||
['asdf', 10], | ||
@@ -115,2 +115,3 @@ ['asdf', 5] | ||
var inputs = [ | ||
['', 9], | ||
['asdfasdfasdf', 10], | ||
@@ -147,2 +148,3 @@ ['t'] | ||
var inputs = [ | ||
['', 9], | ||
['asdfasdf', 10], | ||
@@ -177,2 +179,3 @@ ['123', 4] | ||
var inputs = [ | ||
['', 9], | ||
['123', 3] | ||
@@ -208,2 +211,3 @@ ]; | ||
var inputs = [ | ||
['', 'Adam Smith'], | ||
['John Smith', 'John Smith'], | ||
@@ -243,2 +247,3 @@ [10, 10], | ||
var inputs = [ | ||
'', | ||
'123', | ||
@@ -287,2 +292,3 @@ '123456', | ||
var inputs = [ | ||
'', | ||
'07812123456' | ||
@@ -319,2 +325,3 @@ ]; | ||
var inputs = [ | ||
'', | ||
'1980-02-29' | ||
@@ -357,2 +364,3 @@ ]; | ||
var inputs = [ | ||
'', | ||
'1980-02-29', | ||
@@ -405,2 +413,3 @@ '2014-11-05', | ||
var inputs = [ | ||
['', '2014-12-15'], | ||
['2014-12-16', '2014-12-15'], | ||
@@ -471,2 +480,3 @@ ['2014-11-05', 1, 'day'], | ||
var inputs = [ | ||
'', | ||
'1' | ||
@@ -483,2 +493,2 @@ ]; | ||
}); | ||
}); |
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
59856
1474
60