0

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?

Thinker
  • 5,326
  • 13
  • 61
  • 137

1 Answers1

0

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:

lovubuntu
  • 979
  • 9
  • 16