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

scripts/classes/ValidText/classValidText.ts   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 27
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
mnd 2
bc 2
fnc 2
dl 0
loc 27
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A classValidText.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