skip to Main Content

I am trying to use an HTML form <input> to validate to conform to a string with 7-30 characters and requires at least one letter and one number (but use of other characters is allowed).

The vendor that holds our account data provided me with this regular expression for password validation: (?=.{7,30})(?=.*[a-zA-Z])(?=.*[d])(?!.*(?:=))

When I try to use this like so:

<input type="password" name="register_password" pattern="(?=.{7,30})(?=.*[a-zA-Z])(?=.*[d])(?!.*(?:=))" required>

…nothing I enter into the field will validate. It just throws this no matter what I try:

html5 password validation not passing

Would someone please let me know what the proper format for the pattern attribute should be?

2

Answers


  1. Sometimes the use of lookahead assertions in the pattern attribute is not supported all browsers. Change your browser run this code again.

    Login or Signup to reply.
  2. Your pattern is entirely lookaheads, it doesn’t have anything to match the input string itself. Since the pattern attribute is automatically anchored at both ends (it must match the entire string), this means it will only match a zero-length input that also begins with 7-30 characters and contains a letter and number — obviously these are contradictory.

    Take .{7,30} out of the lookahead and put it after the other lookaheads.

    <form>
      <input pattern="(?=.*[a-zA-Z])(?=.*d)(?!.*(?:=)).{7,30}">
    </form>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search