-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsEDIPI.js
78 lines (67 loc) · 2.05 KB
/
clsEDIPI.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
class clsEDIPI
{
constructor(options)
{
if (!options)
{
throw 'Options must be defined for the EDIPI class';
}
this.options = options;
this.createElement();
}
createElement()
{
let containerContent =
`<div class="TEAMclsEDIPIContainer">
<input class="TEAMclsEDIPIInput" type="text" />
<span class="TEAMclsEDIPIAlert">Must be a valid EDIPI.</span>
</div>`;
this.isValid = false;
this.EDIPI = '';
if (typeof this.options.containerElement === 'undefined' || !this.options.containerElement)
{
throw 'Container element must be defined in EDIPI options.';
}
this.containerElement = this.options.containerElement;
this.containerElement.innerHTML = containerContent;
this.input =
this.containerElement.querySelector('.TEAMclsEDIPIInput');
this.validationPopover =
this.containerElement.querySelector('.TEAMclsEDIPIAlert');
this.input.addEventListener('input',
this.ValidationTrigger.bind(this));
}
ValidationTrigger()
{
this.EDIPI = this.input.value;
this.Validator(this.EDIPI);
}
Validator(EDIPIToTest)
{
this.isValid = this.EDIPIValidationTest(EDIPIToTest);
const showValidation = EDIPIToTest !== "" && !this.isValid;
this.ValidationDisplay(showValidation);
}
EDIPIValidationTest(EDIPI)
{
return /^(\d(?!1{7}|2{7}|3{7}|4{7}|5{7}|6{7}|7{7}|8{7}|9{7}|0{7}|012345|123456|234567|345678|456789|567890|098765|987654|876543|765432|654321|543210)){10}$/.test(EDIPI);
}
ValidationDisplay(show)
{
if (show)
{
this.validationPopover.style.display = "inherit";
}
else
{
this.validationPopover.style.display = "none";
}
}
Reset()
{
this.input.value = '';
this.EDIPI = '';
this.isValid = false;
this.validationPopover.style.display = "none";
}
}