0

This is my expression:

^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])[[:graph:]]{6,25}$

I have tested it on http://regex101.com/

Its working for string DeepakManwal1 when there is php selected but does not work when javascript is selected. I don't know what is the exact reason.

I want to use this expression for password validation where there should be at-least one uppercase letter and one numeric character.

Here is fiddle http://jsfiddle.net/j7rmj44h/

3 Answers 3

3

It is because of the POSIX class [:graph:] — you could change it to the equivalent [\x21-\x7E]. Also, you need to remove the quotations around your pattern according to your fiddle.

var re = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])[\x21-\x7E]{6,25}$/

Fiddle

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

Comments

2

AFAIK, javascript doesn't understand POSIX.

Have a try with:

 ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])\S{6,25}$

Comments

1

Different regex engines have different capabilities. Only the simplest of regex can be shared across implementations.

If I recall correctly [:graph:] like specification of character classes is not supported in JS.

Comments

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.