Page 1 of 1

validating for alphanumeric, comma, apostrophe and hyphen

Posted: Thu May 25, 2006 12:37 pm
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]

Posted: Thu May 25, 2006 3:17 pm
by feyd
yes, you're on the right track.