Thanks to S. Gehrig’s answer in the initial question I’ve got a regex which works fine and validates a variable based on the Letter property (except Chinese, but that’s another topic :):
if (preg_match('/^\p{L}+$/u', $input)) {
// OK
}
Unfortunately I can’t extend it to support to support numbers respective question/exclamation & co. My experiments included:
'/^[\p{L}]|[0-9]|[\n]|[']|[\?]|[\!]|[\.]|[\,]+$/u'
'/^[\p{L}+]|[0-9]|[\n]|[']|[\?]|[\!]|[\.]|[\,]$/u'
'/^[\p{L}+]|[0-9]|[\n]|[']|[\?]|[\!]|[\.]|[\,]$/u'
What is the correct regex? Please point me in the right direction.
Many, many thanks!
\p{L}+is already “non-empty string of\p{L}‘s”.[]on the other hand indicate “one of”, thus depending on your actual requirements, either of this should work:Any (positive, non-zero) number of the specified characters in sequence:
Either a sequence of
\p{L}s or a sequence of mixed[0-9\n'?!.,]:Either a sequence of
\p{L}s or exactly one of[0-9\n'?!.,]: