1

Any thoughts as to why https://codepen.io/anon/pen/qVbjGa:

<form>
    <input type="text" name="formField" title="Password must be at least eight characters in length, contain at least one capital letter, one number, and one special character." 
           pattern="\A(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])(?=.*[\d]).{8,}\z" required />
    <input type="submit" value="Submit" />
</form>

wouldn't work and http://rubular.com/r/9oIgojECMf would?

1 Answer 1

2

You must replace the beginning of the input \A with ^ and the end of input from \z to $

<form>
  <input
    type="text"
    name="formField"
    title="Password must be at least eight characters in length, contain at least one capital letter, one number, and one special character." 
    pattern="(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])(?=.*[\d]).{8,}"
    required />
  <input type="submit" value="Submit" />
</form>

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

7 Comments

Thank you so much! Will accept answer as soon as I can!
@Drew You may consider that funny but you do not need any ^ and $ - remove them and pattern="(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])(?=.*\d).{8,}" will work the same.
There is no need to use ^ and $ in the HTML5 pattern attribute regex, remove the anchors since they are added automatically by the engine.
You're right @WiktorStribiżew, I've updated the answer, thank you.
What are you trying to do with [W_] and [d] @Drew?
|

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.