I would like to allow in any charsets (latin, hebrew, cyrillic but not unicode emojis) all letter and minus (-), but it should not allow to use the minus more then once per time and not on start and end:
YaMo -> OK
Ya-Mo -> OK
Ya-Mo-Ga -> OK
Ya--Mo -> FALSE
Ya---Mo -> FALSE
-Ya -> FALSE
-Ya-Mo- -> FALSE
Ya- -> FALSE
Yo-Mo- Mo -> FALSE
Yo-Mo -Go -> FALSE
So far I have:
preg_match('/^[\p{L} -]+$/', $post['firstname'])
It don't take care about multiple occurence and if is on start or end. Exist there any regex approach to do it?
As workaround I now check with substr first and last letter != '-' and check with strpos for '--'.
the proposed similiar duplicate is wrong, as it not work as it should, it allow: Yo-Mo- Mo