vendredi 22 mars 2019

Angular Validator Pattern works in HTML but not in TypeScript

Following Regular Expression does work in HTML like following example:

<input type="text" formControlName="mgmtIP" class="input-text" pattern="([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])">

But if I want to put that pattern in the FormGroup, the Validator isn't recognized:

mgmtIP: [host.mgmtIP, [
            Validators.required,
            Validators.pattern(/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/)
          ]],

I tried putting it in a string with taking away the ^ and the $. That didn't work neither

Aucun commentaire:

Enregistrer un commentaire