validate input string with letters numbers and spaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fael097
Forum Commoner
Posts: 34
Joined: Sat Mar 06, 2010 7:57 pm

validate input string with letters numbers and spaces

Post 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!
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: validate input string with letters numbers and spaces

Post by rahulzatakia »

Hi, use the following code:

Code: Select all

$element = "xyz123 ";
preg_match("/^[a-zA-Z0-9 ]+$/",$element);
fael097
Forum Commoner
Posts: 34
Joined: Sat Mar 06, 2010 7:57 pm

Re: validate input string with letters numbers and spaces

Post by fael097 »

thanks mate, works like a charm!
Post Reply