Regex - With Space and Special Characters

耗尽温柔 提交于 2019-11-29 16:44:19

add characters to your regex code like this~

^[a-zA-Z0-9 !@#$%^&*)(]{2,20}$

the \s is not only express space..

Try ^[a-zA-Z0-9 ]{2,20}$.

And are you sure your original expression worked? The quantifier {2,20} is only applied to the \s, and not to your set inside [].

Regarding the second part of your question, just put those characters inside of [], no escaping needed.

All of Special Characters and char and number and with Space

[A-Za-z0-9-.& ,+!@#$%\^*();\/|<>"'?=:\t_\n[]{}~`]

*** Regex for all types of special characters and normal characters too with space in between them.

Declare the below in some variable and perform your task:

/^[a-zA-Z0-9 !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{2,20}$/

*** Regex for all types of special characters with spaces:

/^[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{2,20}$/

(answer is tried and tested!!)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!