-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseHolyLandPhone.js
181 lines (153 loc) · 3.97 KB
/
ParseHolyLandPhone.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* @author Mordi Sacks
* @class ParseHolyLandPhone
*/
export default class ParseHolyLandPhone {
constructor(phoneNumber) {
this.phoneNumber = phoneNumber;
this.fromInternational();
}
static create(phoneNumber) {
return new ParseHolyLandPhone(phoneNumber);
}
/**
* Checks if phone number is a valid Israeli/Palestinian phone number
*
* @return boolean
*/
isValid() {
return this.phoneNumber.match(/^((0[23489][2356789]|0[57][102345689]\d|1(2(00|12)|599|70[05]|80[019]|90[012]|919))\d{6}|\*\d{4})$/) !== null;
}
/**
* Checks if phone number is Israeli
*
* @return boolean
*/
isIsraeli() {
return this.phoneNumber.match(/^((0[23489][356789]|0[57][1023458]\d|1(2(00|12)|599|70[05]|80[019]|90[012]|919))\d{6}|\*\d{4})$/) !== null;
}
/**
* Checks if phone number is Palestinian
*
* @return boolean
*/
isPalestinian() {
return this.phoneNumber.match(/^(0[23489]2|05[69]\d|)\d{6}$/) !== null;
}
/**
* Checks if phone number is land line
*
* @return boolean
*/
isLandLine() {
return this.phoneNumber.match(/^0([23489][2356789]|7\d{2})\d{6}$/) !== null;
}
/**
* Checks if phone number is mobile
*
* @return boolean
*/
isMobile() {
return this.phoneNumber.match(/^0[5][102345689]\d{7}$/) !== null;
}
/**
* Checks if phone number is special (*1234)
*
* @return boolean
*/
isSpecial() {
return this.phoneNumber.match(/^\*\d{4}$/) !== null;
}
/**
* Checks if phone number is business (1800, etc)
*
* @return boolean
*/
isBusiness() {
return this.phoneNumber.match(/^1(2(00|12)|599|70[05]|80[019]|90[012]|919)\d{6}$/) !== null;
}
/**
* Checks if phone number is toll free (1800)
*
* @return boolean
*/
isTollFree() {
return this.phoneNumber.match(/^180[019]\d{6}$/) !== null;
}
/**
* Checks if phone number is premium (1900)
*
* @return boolean
*/
isPremium() {
return this.phoneNumber.match(/^19(0[012]|19)\d{6}$/) !== null;
}
/**
* Checks if phone number is Kosher (phone supports only calls)
*
* @return boolean
*/
isKosher() {
return this.phoneNumber.match(/^0([23489]80|5041|5271|5276|5484|5485|5331|5341|5832|5567)\d{5}$/) !== null;
}
/**
* Checks if phone number is erotic (1919)
*
* @return boolean
*/
isErotic() {
return this.phoneNumber.match(/^1919\d{6}$/) !== null;
}
/**
* Checks if phone number can receive sms
*
* @return boolean
*/
isSmsable() {
return this.isNotKosher() && this.isMobile();
}
fromInternational() {
this.phoneNumber = this.phoneNumber.replace(/^(972)(\d{8,9})$/, '0$2');
}
/**
* Returns phone number transformed to international format
* 021231234 > 97221231234
* 0501231234 > 972501231234
*/
getInternational() {
return this.phoneNumber.replace(/^(0)(\d{8,9})$/, '972$2');
}
isNotValid() {
return !this.isValid();
}
isNotIsraeli() {
return !this.isIsraeli();
}
isNotPalestinian() {
return !this.isPalestinian();
}
isNotLandLine() {
return !this.isLandLine();
}
isNotMobile() {
return !this.isMobile();
}
isNotBusiness() {
return !this.isBusiness();
}
isNotTollFree() {
return !this.isTollFree();
}
isNotPremium() {
return !this.isPremium();
}
isNotKosher() {
return !this.isKosher();
}
isNotErotic() {
return !this.isErotic();
}
isNotSmsable() {
return !this.isSmsable();
}
}