Passed
Pull Request — master (#36)
by
unknown
01:55
created

classValidText.checkValidText   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 18
rs 9.7
c 0
b 0
f 0
cc 2
1
/**
2
 * classValidText is where we check if the text input is valid
3
 * If it is, we enable the submit button
4
 */
5
export default class classValidText {
6
  /**
7
   * Check if the entered text is either in the format "XX12345", is not undefined and length is 7
8
   * @param {Event} event Used to fetch the value from the text input
9
   */
10
  public checkValidText(event: Event) {
11
    // Need to cast this to <HTMLInputElement> or Typescript gives us an error
12
    const bilInformasjon = (<HTMLInputElement>event.target).value;
13
    const submitButton = window.document.getElementById('submitButton');
14
    const letters = /[A-Z]{2}[0-9]{5}/gi;
15
16
    if (
17
      bilInformasjon.match(letters) &&
18
      bilInformasjon !== undefined &&
19
      bilInformasjon.length === 7
20
    ) {
21
      submitButton!.removeAttribute('disabled');
22
    } else {
23
      submitButton!.setAttribute('disabled', 'true');
24
    }
25
  }
26
}
27