I am trying to validate password field such that it accepts characters, numbers and also special characters. It must accept exactly 8 characters . I have searched for it in the internet but I was not able to get any specific answer and if getting its not working.
Let me just give an explanation of the characters the password must accept: AZ, az, 0-9, ~!@#$%^&*()_-+=.|<>?{}[]
So, valid password would be: ankit@19
, a_g-1#87
, etc. Invalid password would be: ag/ i(91
(because it is having space and ' /
' in it)
The regular expression I am using right now is:
/^[A-Za-z0-9?=\.~!@#\$%^&*()_-|<>{}\[\]]{8}$/
This one is not working at all. Please help me to get the right way to do this.
^[A-Za-z0-9?=.~!@#\$%^&*()_|<>{}\[\]-]{8}$
You need to take -
at the end and escape []
inside []
.
See demo.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.