Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

movepixels's avatar

Regex Validation Help

I am trying to validate a field allowing a-z and some common punctuation , . - ' in addition to international unicode characters.

I tried various ways and all fail. This is where I left off with my attempt

$regexp = "/^[a-zA-Z ,-'. \p{L}]+$/ui"; 

Any help would be appreciated.

Thanks, Dave

0 likes
3 replies
papa's avatar

Try this

[a-zA-Z,\-'.()*\p{L}]
movepixels's avatar

I have this in the custom validator but still failing

$regexp = "/^[a-zA-Z,\-'.()*\p{L}]+$/u"; 
return preg_match($regexp, $value);
movepixels's avatar

Ok I think this is working, but I suck at regex so hoping community can advise if any issues with this.

$regexp = "/^[a-zA-Z, \-'.\p{L}]+$/ui"; 
return preg_match($regexp, $value);

I only want to allow a-zA-Z, unicode letter characters \p{L} and a few common punctuation characters like - , ' .

Thanks again!

Dave

Please or to participate in this conversation.