0

I have problem to validate white space in angular 7 input pattern.

<form #f="ngForm">
    <mat-form-field floatLabel="always">
        <input type="text" pattern="[a-zA-Z0-9_-\s]+" required matInput name="folderName">
    </mat-form-field>
    </form>
<button mat-raised-button [disabled]="!f.valid">Create</button>

I tried with:

  • pattern="[a-zA-Z0-9_-\s]+" Create button get disabled first time I add space
  • pattern="[a-zA-Z0-9_- ]+" I get message "Invalid regular expression" from angular. Here is a white space after '-' in pattern and that is invalid.

Where I am wrong ?

Milos
  • 1,678
  • 4
  • 23
  • 49

0 Answers0