简体   繁体   中英

A regular expression that allow whitespace, coma , dot, numbers and any letters?

My code:

if( preg_match( '/^[a-zA-Z0-9,.!? ]*$/', '.,!? a ' ) ) {
echo 'contains numbers, dot, coma, whitespace or latin letters<br/>'
}

But would be false if contains žы .

This

if ( preg_match("/^\p{L}+$/u", 'žы') ) {
echo 'Contains any letters<br/>';
}

How to combine both, so that allow any letters (also non latin), numbers, dot, coma, whitespace?

您只需将它们结合起来:

/^[,.!? \d\pL]*$/u

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM