Page 1 of 1

validate input string with letters numbers and spaces

Posted: Wed Jun 23, 2010 2:29 pm
by fael097
hi, i need a pregmatch that validades a string from a field with numbers, letters, and spaces only. maybe i could use dashes, commas and accented letters later, but i dont know anything about regex, and its kinda hard to learn it with the available tutorials, so i'd be happy to have just my first need.
someone can help?
thanks!

Re: validate input string with letters numbers and spaces

Posted: Thu Jun 24, 2010 8:56 am
by rahulzatakia
Hi, use the following code:

Code: Select all

$element = "xyz123 ";
preg_match("/^[a-zA-Z0-9 ]+$/",$element);

Re: validate input string with letters numbers and spaces

Posted: Fri Jun 25, 2010 7:19 am
by fael097
thanks mate, works like a charm!