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

classValidText   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A checkValidText 0 18 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