regexspecial-charactersletters

Regex - With Space and Special Characters


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

The input length must be a least 2 characters and maximum 20 characters.

I also want to enable space in the input, but only space, not new line, etc.

Last thing I have problem with is that I want to enable characters such as !@#$%^&*)(


Solution

  • add characters to your regex code like this~

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

    the \s is not only express space..