...

View Full Version : preg_match help



koolaid
01-14-2008, 07:51 PM
Hello,

I need a little help with preg_match / regexp, I want only a-z, A-Z (capitals) and 0-9 to be used in $str,

What I've got so far:


preg_match("[a-zA-Z0-9]", $str)

This doesn't work, and I'm not exactly a regexp whiz...

StupidRalph
01-14-2008, 07:54 PM
You'll probably be better off using ctype_alnum (http://www.php.net/ctype)().

StupidRalph
01-14-2008, 07:55 PM
Wait, unless you were trying to capture the string...I was reading another thread with RegEx and they were using it as validation...

Inigoesdr
01-14-2008, 08:34 PM
$string = 'test1234';

$count = preg_match('/[^A-z0-9]/', $string);
if(!empty($count))
{
echo 'invalid string';
}
else
{
echo 'valid string';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum