mirror of
https://gitlab.silvrtree.co.uk/martind2000/node-validator.git
synced 2025-01-10 21:05:08 +00:00
Updated phone validator to return empty for null or undefined objects
This commit is contained in:
parent
1e7e87a62d
commit
fdfb9bc71b
46
.jscsrc
Normal file
46
.jscsrc
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"disallowKeywords": ["with"],
|
||||||
|
"disallowKeywordsOnNewLine": ["else"],
|
||||||
|
"disallowMixedSpacesAndTabs": true,
|
||||||
|
"disallowMultipleVarDecl": "exceptUndefined",
|
||||||
|
"disallowNewlineBeforeBlockStatements": true,
|
||||||
|
"disallowQuotedKeysInObjects": true,
|
||||||
|
"disallowSpaceAfterObjectKeys": true,
|
||||||
|
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||||
|
"disallowSpacesInFunction": {
|
||||||
|
"beforeOpeningRoundBrace": true
|
||||||
|
},
|
||||||
|
"disallowSpacesInsideParentheses": true,
|
||||||
|
"disallowTrailingWhitespace": true,
|
||||||
|
"maximumLineLength": 160,
|
||||||
|
"requireCamelCaseOrUpperCaseIdentifiers": false,
|
||||||
|
"requireCapitalizedComments": true,
|
||||||
|
"requireCapitalizedConstructors": true,
|
||||||
|
"requireCurlyBraces": true,
|
||||||
|
"requireSpaceAfterKeywords": [
|
||||||
|
"if",
|
||||||
|
"else",
|
||||||
|
"for",
|
||||||
|
"while",
|
||||||
|
"do",
|
||||||
|
"switch",
|
||||||
|
"case",
|
||||||
|
"return",
|
||||||
|
"try",
|
||||||
|
"catch",
|
||||||
|
"typeof"
|
||||||
|
],
|
||||||
|
"requireSpaceAfterLineComment": true,
|
||||||
|
"requireSpaceAfterBinaryOperators": true,
|
||||||
|
"requireSpaceBeforeBinaryOperators": true,
|
||||||
|
"requireSpaceBeforeBlockStatements": true,
|
||||||
|
"requireSpaceBeforeObjectValues": true,
|
||||||
|
"requireSpacesInFunction": {
|
||||||
|
"beforeOpeningCurlyBrace": true
|
||||||
|
},
|
||||||
|
"requireTrailingComma": false,
|
||||||
|
"requireEarlyReturn": false,
|
||||||
|
"validateIndentation": 2,
|
||||||
|
"validateLineBreaks": "LF",
|
||||||
|
"validateQuoteMarks": "'"
|
||||||
|
}
|
@ -265,6 +265,11 @@ VALIDATE = new function() {
|
|||||||
this.validatePhone = function(params) {
|
this.validatePhone = function(params) {
|
||||||
var onlyDigits;
|
var onlyDigits;
|
||||||
var uk, v, required, itrx;
|
var uk, v, required, itrx;
|
||||||
|
|
||||||
|
if ((typeof params === 'undefined') || (typeof params === 'object' && params === null)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof params === 'object') {
|
if (typeof params === 'object') {
|
||||||
uk = params.uk || false;
|
uk = params.uk || false;
|
||||||
v = params.number;
|
v = params.number;
|
||||||
|
@ -9,6 +9,16 @@ describe('Phone Validator', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not validate an non existing object', function(done) {
|
||||||
|
assert.equal($V.validatePhone(), '');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not validate an null object', function(done) {
|
||||||
|
assert.equal($V.validatePhone(null), '');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('should validate an normal uk number', function(done) {
|
it('should validate an normal uk number', function(done) {
|
||||||
assert.equal($V.validatePhone({number: '01389 602001', uk: true}),
|
assert.equal($V.validatePhone({number: '01389 602001', uk: true}),
|
||||||
'01389602001');
|
'01389602001');
|
||||||
|
Loading…
Reference in New Issue
Block a user