Total Complexity | 8 |
Complexity/F | 2 |
Lines of Code | 31 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | const f12phone = { |
||
|
|||
2 | validatePhone(value, messages, options) { |
||
3 | value = value.replace(/_|-| |\(|\)|\+/g, ''); |
||
4 | if (this.isEmpty(value)) { |
||
5 | return; |
||
6 | } |
||
7 | if (!this.isNumeric(value)) { |
||
8 | this.addMessage(messages, f12_phone_error_format, value); |
||
9 | return; |
||
10 | } |
||
11 | value = value.replace(/\D/g, ''); |
||
12 | if (value.length > 15 || value.length < 11) |
||
13 | this.addMessage(messages, f12_phone_error_length, value); |
||
14 | }, |
||
15 | addMessage(messages, message, value) { |
||
16 | messages.push(message.replace(/\{value\}/g, value)); |
||
17 | }, |
||
18 | isEmpty(value, trim) { |
||
19 | return value === null || value === undefined || value == [] |
||
20 | || value === '' || trim && $.trim(value) === ''; |
||
21 | }, |
||
22 | |||
23 | isNumeric(str) { |
||
24 | /** |
||
25 | * https://stackoverflow.com/questions/175739/how-can-i-check-if-a-string-is-a-valid-number |
||
26 | */ |
||
27 | if (typeof str != "string") return false // we only process strings! |
||
28 | return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)... |
||
29 | !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail |
||
30 | } |
||
31 | } |
||
32 | |||
34 |