简体   繁体   English

如何使用jQuery正则表达式验证字符,数字和特殊字符?

[英]How to validate characters, numbers and special characters using jQuery regular expression?

I am trying to validate password field such that it accepts characters, numbers and also special characters. 我正在尝试验证密码字段,使其接受字符,数字以及特殊字符。 It must accept exactly 8 characters . 它必须正好接受8个字符 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, ~!@#$%^&*()_-+=.|<>?{}[] 让我仅说明密码必须接受的字符: 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) 因此,有效密码将为: ankit@19a_g-1#87等。无效密码将为: ag/ i(91 (因为其中包含空格和' / ')

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. 参见演示。

https://regex101.com/r/mG8kZ9/13 https://regex101.com/r/mG8kZ9/13

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM