validating for alphanumeric, comma, apostrophe and hyphen

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
gpinet
Forum Newbie
Posts: 1
Joined: Thu May 25, 2006 12:25 pm

validating for alphanumeric, comma, apostrophe and hyphen

Post by gpinet »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I created a function to validate the data of an html form. I only want users to type alphanumeric characters, commas, apostrophes and hyphen. Nothing else.

I just can't seem to figure out how to do it properly....

Here is the function that I created:

Code: Select all

function is_alphanumeric($test) {
	return (preg_match("/^[A-Za-z0-9\,'\-]+/", $test));
	}
Am I on the right track?

Any help is appreciated,

Gilles


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, you're on the right track.
Post Reply