Passed
Pull Request — master (#223)
by Daniel
01:42
created

scripts/classes/ValidText/classValidText.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 29
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 20
mnd 1
bc 1
fnc 0
dl 0
loc 29
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
interface SubmitButton extends HTMLElement {
2
  removeAttribute(name: string): void;
3
  setAttribute(name: string, value: string): void;
4
}
5
6
/**
7
 * checkValidText is where we check if the text input is valid
8
 * If it is, we enable the submit button
9
 */
10
11
const checkValidText = (event: Event): void => {
12
  const bilInformasjon = event.target as HTMLInputElement;
13
14
  const submitButton = window.document.getElementById(
15
    "submitButton"
16
  ) as SubmitButton;
17
18
  const letters = /[A-Z]{2}\d{5}/gi;
19
  const bilInformasjonMatchesFormat = letters.test(bilInformasjon.value);
20
21
  if (bilInformasjonMatchesFormat && bilInformasjon !== undefined) {
22
    submitButton.removeAttribute("disabled");
23
  } else {
24
    submitButton.setAttribute("disabled", "true");
25
  }
26
};
27
28
export default checkValidText;
29