Hi all,
I have the following:
Which accepts Hello4 as valid inputPHP Code:
if(!preg_match("/^[a-zA-Z0-9\s]+$/",$value))
But I need it to allow any punctuation too i.e. !?/\<>.,'"@()[]
Is there a character/modifier for this?
Thanks
Chris.![]()
Hi all,
I have the following:
Which accepts Hello4 as valid inputPHP Code:
if(!preg_match("/^[a-zA-Z0-9\s]+$/",$value))
But I need it to allow any punctuation too i.e. !?/\<>.,'"@()[]
Is there a character/modifier for this?
Thanks
Chris.![]()
Hey Chris,
As far as I know, there are no shorthand sequences for punctuation, but you can definitely still achieve that same effect through creating a character class.
For example, if you wanted the code you posted to include those punctuation characters you listed too, you'd change the pattern to the following:
Note that only the -, \, ] and ^ characters need to be escaped within a character class.Code:/^[a-zA-Z0-9\s!?/\\<>.,'"@()[\]\-]+$/
I wonder what you're trying to prohibit or search for with this pattern? It might be easier to create a negative class and list any characters you don't want rather than all the characters you do.
Bookmarks