I wonder whether someone may be able to help me please.
I'm using the following preg match expression as part of my field validation.
(!preg_match('/^$|^[A-Za-z0-9 .,;-]{5,60}$/', $address4))
The problem I'm having is that I'm unable to get this to work when I include an apostrophe as part of the characters I want to allow.
I've read a number of tutorials and have tried the following without any success, so I'm clearly doing something wrong:
(!preg_match('/^$|^[A-Za-z0-9 .,;-\']{5,60}$/', $address4)),
and
(!preg_match('/^$|^[A-Za-z0-9 .,;-\'\]{5,60}$/', $address4))
I just wondered whether someone could possibly look at this please and let me know where I've gone wrong.
The minus character in the character class of your regex must always be at the end. Otherwise it will be taken for a character range. So try to switch the apostrophe and the minus:
preg_match('/^$|^[A-Za-z0-9 .,;\'-]{5,60}$/', $address4)