Debt Help - Mobile Phone - Free Myspace Layouts - Samsung - Dietary Supplements

PDA

View Full Version : How to check if string is a-Z 0-9 and -


Psychotomus1
Oct 2nd 2007, 10:17 pm
how can I check if a string is a-Z 0-9 and the - symbol.

kendo1979
Oct 2nd 2007, 10:56 pm
use preg_match

preg_match ( string pattern, string subject [, array &matches [, int flags [, int offset]]] )

krt
Oct 2nd 2007, 11:32 pm
The pattern you need is /^[a-z0-9-]+$/i or you can do the opposite:
if (!preg_match("/[^a-z0-9-]/", ...

Psychotomus1
Oct 2nd 2007, 11:56 pm
thanks krt.