Modified validatePhone to accept a string or an object. If it is a string, it handles it as a UK phone number.

This commit is contained in:
Martin Donnelly 2016-03-16 11:04:34 +00:00
parent 5dd441a06e
commit 7100cf5ed2
3 changed files with 30 additions and 19 deletions

View File

@ -7,7 +7,8 @@
*
*/
/* exported VALIDATE */
var VALIDATE = new function() {
var VALIDATE;
VALIDATE = new function() {
this.dateBuilder = function(d, m, y) {
return new Date(Date.UTC(y, m, d, 0, 0, 0));
@ -278,10 +279,20 @@ var VALIDATE = new function() {
* @returns {string}
*/
this.validatePhone = function(params) {
var uk = params.uk || false;
var v = params.number;
var required = params.req || false;
var itrx;
var uk, v, required, itrx;
if (typeof params === 'object') {
uk = params.uk || false;
v = params.number;
required = params.req || false;
}
if (typeof params === 'string') {
uk = true;
v = params;
required = false;
}
var onlyDigits = function(inval) {

View File

@ -1,6 +1,6 @@
{
"name": "node-validator",
"version": "0.1.0",
"version": "0.1.1",
"description": "A collection of validators.",
"main": "md-validator.js",
"scripts": {

View File

@ -21,9 +21,9 @@ describe('Phone Validator', function() {
done();
});
it('should validate a bracketted uk number', function(done) {
assert.equal($V.validatePhone({number: '(0)1389 602003', uk: true}),
'01389602003');
it('should validate a number with no options', function(done) {
assert.equal($V.validatePhone('01389 602001'),
'01389602001');
done();
});