...

View Full Version : Preg_match



david07
11-30-2006, 02:39 PM
I can not figure out how to preg_match to allow for only
1.character from A-Z regardless of case
2.And to allow for numeric characters as well
3.Not allow whitespace or any other characters


if (preg_match ('[^0-9]',$input))
{
}
else{

Any help much appreciated.

GJay
11-30-2006, 02:56 PM
your description needs to be more clear, it's a bit ambiguous.


//a single letter or number
$pattern='#^[a-z0-9]$#i';

//1 or more (letters or numbers)
$pattern='#[a-z0-9]+#i';

//a single letter followed by 1 or more numbers
$pattern='#[a-z][0-9]+#i';


the 'i' in each case tells it to be case-insensitive.

david07
12-01-2006, 08:58 AM
Thanks Gjay for your response.

Your code is great, but its still not taking into consideration any whitespace.

So basicaly it allows user to put space between characters.

hmm preg_match seems to b a programming language on its own *jokes.

chump2877
12-01-2006, 11:04 AM
if (preg_match ('/^([a-zA-Z0-9]+)$/',$input) == 1 && preg_match('/\s+/',$input) == 0)
{

}
else
{

}

preg_match returns "1" if a match is found, "0" if no match is found....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum