Regex - With Space and Special Characters

后端 未结 5 1246
臣服心动
臣服心动 2020-12-22 02:49

I\'m using the following Regex ^[a-zA-Z0-9]\\s{2,20}$ for input

  • Letters A - Z
  • Letters a - z
  • Numbers 0 - 9

The inp

相关标签:
5条回答
  • 2020-12-22 03:01

    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 [].

    0 讨论(0)
  • 2020-12-22 03:01

    *** 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!!)

    0 讨论(0)
  • 2020-12-22 03:16

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

    0 讨论(0)
  • 2020-12-22 03:19

    add characters to your regex code like this~

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

    the \s is not only express space..

    0 讨论(0)
  • 2020-12-22 03:26

    All of Special Characters and char and number and with Space

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

    0 讨论(0)
提交回复
热议问题