Skip to content Skip to sidebar Skip to footer

Javascript Regex That Requires One Uppercase Letter, One Lowercase Letter And One Number, And Allows Special

I'm trying to make a regex to check a password field, I want to require at least one uppercase letter, one lower case letter and one number. I also want to allow the user to use sp

Solution 1:

If you don't want special characters to be a requirement, there is no point validating it.

This regex should do: /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).*$/

Note that this regex will not validate properly for characters not in the default ascii range of a-zA-Z. So if my password was åäöÅÄÖ1234 it would not be valid for this regex, even though there are upper case and lower case letters.

A possible solution, if this is a requirement, would be to rewrite using unicode properties.

Demo: http://regex101.com/r/uO6jB5

Solution 2:

From this page:

"Password matching expression. Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit."

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$

(note: you'll want to test this to be sure.)

Post a Comment for "Javascript Regex That Requires One Uppercase Letter, One Lowercase Letter And One Number, And Allows Special"