Regex for password verification

I've looked at some ideas here, but I still seem to be struggling with a regex coming up to suit my requirements.

I need regex to check password format, criteria:

  • At least 1 uppercase letter
  • At least 1 room
  • Alphanumeric characters only (no special characters)
  • At least 8 characters

I am using regex:

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

      

However, this also allows the use of type characters !$&

.

Is there some modification I need to make in order to make it stop accepting these special characters?

+3


source to share


1 answer


Change the last part .{8,}

to[a-zA-Z\d]{8,}



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

      

+8


source







All Articles