I have a variable which has to allow only numbers , dashes and parenthesis, there is no particular length for phone number , And the validation must be done in php , no javascript allowed,
EDIT
Just wanted to allow spaces too to the regular expressions….
Thanks
So, I am a bit confused about the question here, but I’ll give it a shot and hopefully it gets you to where you need to be.
This will allow anything containing the specified characters.
(303)123-4567will be allowed. As will32084248())(21324234--234242-23-(clearly not a phone number)If you want to make the regex a bit more strict, we can limit to US-style numbers:
This will only allow US style numbers with an optional country code.