This repository was archived by the owner on Dec 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathValidationUtil.js
142 lines (142 loc) · 4.58 KB
/
ValidationUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A ValidationUtility class that has several static methods to assist in development.
*
* @class ValidationUtil
* @module StructureJS
* @submodule util
* @author Robert S. (www.codeBelt.com)
* @static
*/
var ValidationUtil = (function () {
function ValidationUtil() {
throw new Error('[ValidationUtil] Do not instantiate the ValidationUtil class because it is a static class.');
}
/**
* Determines if the String passed has a length.
*
* @method isEmpty
* @param value {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isEmpty('sometext');
* // false
*/
ValidationUtil.isEmpty = function (value) {
if (value != null) {
return value.length < 1;
}
return true;
};
/**
* Determines if the two values passed in are the same.
*
* @method isMatch
* @param value1 {any}
* @param value2 {any}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isMatch('[email protected]', '[email protected]');
* // false
*/
ValidationUtil.isMatch = function (value1, value2) {
return value1 === value2;
};
/**
* Determines if the String passed in is a valid email address.
*
* @method isValidEmailAddress
* @param email {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isValidEmailAddress('[email protected]');
* // true
*/
ValidationUtil.isValidEmailAddress = function (email) {
var expression = /^[-a-zA-Z0-9+_\'][-.a-zA-Z0-9+_\']*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.([a-zA-Z]{2,})$/;
return expression.test(email);
};
/**
* Determines if the String passed in is a phone number.
*
* @method isValidPhoneNumber
* @param phoneNumber {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isValidPhoneNumber('123 456 7899');
* // true
*/
ValidationUtil.isValidPhoneNumber = function (phoneNumber) {
var expression = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})$/;
return expression.test(phoneNumber);
};
/**
* Determines if the String passed in is a zip code.
*
* @method isZipCode
* @param zipCode {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isZipCode('55067 4434');
* // true
*/
ValidationUtil.isZipCode = function (zipCode) {
var expression = /^([0-9]{5})(?:[-\s]*([0-9]{4}))?$/;
return expression.test(zipCode);
};
/**
* Determines if the String passed in is a postal code.
*
* @method isPostalCode
* @param postalCode {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isPostalCode('p8n3h3');
* // true
*/
ValidationUtil.isPostalCode = function (postalCode) {
var expression = /^([A-Z][0-9][A-Z])\s*([0-9][A-Z][0-9])$/i;
return expression.test(postalCode);
};
/**
* Determines if the String passed in is a Social Security Number.
*
* @method isSocialSecurityNumber
* @param ssn {string}
* @returns {boolean}
* @public
* @static
* @example
* ValidationUtil.isSocialSecurityNumber('178051120');
* // true
*/
ValidationUtil.isSocialSecurityNumber = function (ssn) {
var expression = /^\d{3}-?\d{2}-?\d{4}$/;
return expression.test(ssn);
};
return ValidationUtil;
}());
exports.default = ValidationUtil;
});