Reputation: 5784
I have a custom pattern like this
/^([a-zA-Z0-9@$().'"%#!&{}=+-_\n ]){3,300}$/
to validate user inputs in message box. As you can see I would like to allow some characters entry like @$().'"%#!&{}=+-_\n
which are fine, but not characters like ^<>~
.
But adding the space to expression at ]
is also validating those characters!
As you know, I have to validate the space in a message box. So can you please let me know how to fix this?
Upvotes: 0
Views: 41
Reputation: 1500
Custom pattern like /^([a-zA-Z0-9@$().'"%#!&{}=+\-_\n ]){3,300}$/
Upvotes: 0
Reputation: 670
The problem is not the space character. The problem lies with the "-" (hyphen) you have added between "+" and "_". Hyphens are supposed to denote a range hence they should be escaped when not being used in that context.
The correct regex for you would be:
/^([a-zA-Z0-9@$().'"%#!&{}=+\-_\n ]){3,300}$/
Upvotes: 4