Andris
Andris

Reputation: 1442

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?

Upvotes: 1

Views: 54

Answers (1)

Sverri M. Olsen
Sverri M. Olsen

Reputation: 13283

You just combine them:

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

Upvotes: 2

Related Questions