-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTelephone-Validator.js
More file actions
41 lines (41 loc) · 1.24 KB
/
Telephone-Validator.js
File metadata and controls
41 lines (41 loc) · 1.24 KB
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
function telephoneCheck(str) {
let regexOne = /^(\d{3})([-])(\d{3})([-])(\d{4})$/; //555-555-5555
let regexTwo = /^([(])(\d{3})([)])(\d{3})([-])(\d{4})$/; //(555)555-5555
let regexThree = /^([(])(\d{3})([)])([' '])(\d{3})([-])|(d{4})$/; //(555) 555-5555
let regexFour = /^(\d{3})([' '])(\d{3})([' '])(\d{4})$/; //555 555 5555
let regexFive = /^(\d{10})$/; //5555555555
let regexSix = /^[1]([' '])([(])(\d{3})([)])([' '])(\d{3})([-])|(d{4})$/; //1 555 555 5555
let regexSeven =/^[1]([' '])(\d{3})([-])(\d{3})([-])(\d{4})$/; //1 555-555-5555
let regexEight =/^[1]([' '])(\d{3})([' '])(\d{3})([' '])(\d{4})$/; //1 555 555 5555
let regexNine = /^[1]([(])(\d{3})([)])(\d{3})([-])(\d{4})$/; //1(555)555-5555
if (regexOne.exec(str)) {
return true;
}
else if (str.match(regexTwo)) {
return true;
}
else if (str.match(regexThree)) {
return true;
}
else if (str.match(regexFour)) {
return true;
}
else if (str.match(regexFive)) {
return true;
}
else if (str.match(regexSix)) {
return true;
}
else if (str.match(regexSeven)) {
return true;
}
else if (str.match(regexEight)) {
return true;
}
else if (str.match(regexNine)) {
return true;
}
else {
return false;
}
}