| Total Complexity | 2 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 | } |
||
| 27 |