1

After some updates in my project a input pattern doesn't work anymore. Looks like after update to Ionic 2.1.18 input pattern seems to be broken: This part worked for me before but now Password.valid is always false:

  <ion-item>
    <ion-label floating>Password*</ion-label>
    <ion-input type="password" required [(ngModel)]="regModel.Password" name="Password"
               #Password="ngModel" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d*\w]{5,}$"
               (change)="checkPassword()"></ion-input>
  </ion-item>
  <ion-item no-border no-lines no-margin *ngIf="!Password.valid && Password.dirty" color="danger">
    <small>Five characters minimum,</small>
    <br>
    <small> at least 1 uppercase, 1 lowercase and 1 number {{Password.valid}} {{Password.dirty}}
    </small>
  </ion-item>

Update

Funny thing, some of simple regular expressions work fine, but another - don't, e.g. [a-zA-Z ]* - works fine, \d{5} - don't

1

1 Answer 1

0

Just in case if someone else will happen to encounter problem with Ionic pattern, here is an working example of a password that:

  • contain at least one number
  • at least one special character
  • at least one lowercase character
  • at least one uppercase character

inside .ts file:

export class SignUpPage {
  public PASSWORD_REGEX = `.*(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\\$%\\^&\\*]).*`

 // ...
}

inside HTML:

 <ion-input [(ngModel)]="signUpData.password"
            name="password"
            type="password"
            #password="ngModel"
            [minlength]="10"
            [pattern]="PASSWORD_REGEX"
            required>
 </ion-input>

Note: I've omitted password length check in regex and put inside [minlength] property, so the length can be easily controlled without digging into regex, however, if you want it to be implemented with regex way, use this one: .*(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{10,}) - here user should provide at least 10 characters long password.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I've spent some time trying to figure out what pattern works for strong password validation in Ionic. This one actually does!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.