TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Checking if a string is alphanumeric (http://www.talkphp.com/general/3199-checking-if-string-alphanumeric.html)

Jmz 08-01-2008 09:28 AM

Checking if a string is alphanumeric
 
I was looking for the best way to check if a string is alphanumeric and I found things along the lines of:

PHP Code:

function is_alphanumeric($someString){
return (
preg_match("/[\w\s.]/i"$someString) > 0) ? true false;


But then I found the ctype_alnum function for PHP which should I be using?

The second one seems much better to me :-/

delayedinsanity 08-01-2008 05:43 PM

Use ctype over preg_match where possible, yes.
-m

Aaron 08-01-2008 07:21 PM

THANK YOU

I haven't found that function before... and I hate regex... and I usually cry when I have alphanumeric input fields.

You saved me many hours of crying.


All times are GMT. The time now is 08:52 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0