Hi I wonder whether someone may be able to help me please.
Firstly, I’m very new to this, so please bear with me.
I’ve been working through some of the many tutorials to try and come up with a preg match expression which allows:
- Any alphanumeric,
- Commas,
- Full stops and,
- Spaces
and I’ve come up with the following:
(!preg_match('/^[A-Za-z0-9 _.,]{5,35}$/', $nameofcontact))
In addition to this, because the field is optional, I would also like blank fields to pass the validation and it’s this aspect that I’m having difficulty with.
I just wondered whether someone could perhaps provide some guidance on how I can allow the field to be blank in conjunction with the above parameters.
Many thanks and kind regards
Blank field : ^$
‘Or’ in Regex : |
Use this :