Aditya
Aditya

Reputation: 260

Regex problems (preg_match)

I entered my flyer id as abc in input and stored it in $flyerIDs.

I want to validate that input does not contain anything except spaces, digits and comma and if it does throw error.

I have:

$error = preg_match("/[^\s,0-9]+/gi", $flyerIDs);

$error stores "". Don't understand why.

Upvotes: 0

Views: 59

Answers (2)

revo
revo

Reputation: 48711

You should use preg_match_all() instead of g modifier in PHP.

Upvotes: 0

Kurt
Kurt

Reputation: 396

I don't think "g" is a valid modifier in PHP. Also, "i" would only be needed if matching letters.

$error = preg_match("/[^\s,0-9]+/", $ids);

Upvotes: 3

Related Questions