简体   繁体   中英

Anglular-mdl reactive forms password validation

I have a password field where I need a validation with following rules:

  1. It should be alphanumeric
  2. It should not allow only characters or numbers

      <p> <mdl-textfield label="Password" type="password" formControlName="password1" floating-label pattern="[a-zA-Z0-9]+$" error-msg="Please provide an alpha-numeric password" ></mdl-textfield> </p> 

How should I write my pattern?

One way to solve is using a pipe operator which validates to true if either of the pattern is true. You could try something like this.

([A-Za-z]+[0-9]+)|([0-9]+[A-Za-z]+)

You can read more about this here :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM