I want to check if a variable contains only alphabetical characters and apostrophes (') and dashes (-) and white space ( ) characters. How can do I this with preg_match()
in PHP?
I have /[^a-zA-Z'-\s]/i and it solved without apostroph.
I want to check if a variable contains only alphabetical characters and apostrophes (') and dashes (-) and white space ( ) characters. How can do I this with preg_match()
in PHP?
I have /[^a-zA-Z'-\s]/i and it solved without apostroph.
preg_match('/^[\s\pL'-]+$/',$string)
This is the way I'd do it
//EDIT
Maybe if you have a minimum count of letters, use this:
preg_match("/^[\s\pL'-]{5,}$/",$string) //{x,} ---> x is your min number