Submitted by greggles on
I recently had to validate that input text included only letters, apostrophes and spaces including various accented characters. This was surprisingly tough for me to figure out in PHP.
Some good resources:
- The pcre manual
- The htmlpurifier.org doc on utf8
- The comments on php.net/preg_match
Ultimately what worked for me:
$string = "this is a name' éñƃɹǝƃ";
if (preg_match("/^[ \'\p{L}]+$/iu", $string)) {
print 'matched, dog';
}
else {
print 'did not match, dog';
}
Category:
People Involved:
- Log in to post comments