angularvalidationfrontendform-fields

How do I add a condition to the password form field that must be at least 4 characters otherwise an error


Enter your password
        <input matInput id="signup-credentials-password" type="text" style="color: #999999; font-size: 16px;" 
        #passwordSignup minlength="5" [type]="hide ? 'password' : 'text'">

Solution

  • In your ts file, you can set up password as follows:

    ...
    'password': new FormControl(null, [Validators.required, Validators.minLength(4)])
    ...
    

    You can find an example on this page ===> https://stackblitz.com/edit/angular-reactive-forms-bn9ecb