I am trying to write a function that filteres everything from an input to only letters and the symbol “-“. I want that symbol since the input contains names, and someone may be called Jean-Paul, this is my current code:
if(!preg_match('/^\[a-zA-Z]+$/',$string)) {
// Containing something other than a-z and A-Z
}
$string = 'Jean-Paul'; now gives that the string contains illegal characters, but how can I do so that it accepts “-” ?
If by “filter” you mean delete unwanted characters, then use
or