I'm trying to find a regexp that covers a lot of outcomes, the one I'm using now would be enough if it weren't for a lot of international names having special letters in them as well as hyphens.
The one I'm using now looks like this:
/^[A-Za-zåäöÅÄÖ\s\-\ ]*$/
It allows for hyphens and whitespace but it also allows them at the start or end of the string which I don't want to allow.
I need to modify this to allow:
éýÿüåäö
etc. (preferrably by not having to write them all manually)-
hyphens between words, but not before or after the full stringIt should not allow numbers, which it doesn't already. Since I haven't worked a whole lot with regex construction I'm in the dark on how to achieve this, I've found a lot of solutions that covers one or the other scenario, but not all of the ones I need. I would appreciate the assistance. The regex should work for PHP validation.
EDIT:
$fname = 'Scrooge Mc-Duck'; //Only example string
$fname = trim($fname);
if (!preg_match('/^\p{Lu}\p{Ll}+([ -]+\p{Lu}\p{Ll}+)*$/', $fname)) {
$fnameErr = 'Invalid first name';
}
This outputs the error when using @npinti's solution.