12

I need to validate password with these requirements:-

  • At least 1 Uppercase
  • At least 1 Lowercase
  • At least 1 Number
  • At least 1 Symbol, symbol allowed --> !@#$%^&*_=+-
  • Min 8 chars and Max 12 chars

And got stucked a bit, here's what I have so far.

<form>
Password <input type="text" pattern="/^[a-zA-Z0-9!@#\$%\^\&*_=+-]{8,12}$/g" />
<input type="submit" value="Submit" />
</form>

JSFiddle

2
  • 2
    I hope you’re not using that for anything in the real world? Those password requirements are pretty silly. Anyways, don’t use delimiters; remove the / at the beginning of the pattern and the /g at the end. Commented Jan 16, 2015 at 2:37
  • It's for my company internal use only. Commented Jan 16, 2015 at 2:40

1 Answer 1

25

try this pattern

^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,12}$

Demo

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

2 Comments

Nice use of lookahead!
Thanks! am not very good in regex and thanks for sharing such awesome website as well.

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.