Click to See Complete Forum and Search --> : special characters
salim
08-28-2007, 05:39 AM
Hi
can anybody help me solve this problem.
I need to check my text box for valid alplabets.
that is a-z,A-Z,0-9.
if any other character entered in the box it should reject.
I need the preg_match code for this,tried a lot but nothing is working
thnx
artemis
08-28-2007, 06:07 AM
Something like..
if(preg_match("/[^a-z0-9]/i",$string)){
echo 'Non-alphanumeric characters found';
}
salim
08-29-2007, 11:50 AM
yeh fine
preg_match('/[^a-zA-Z0-9]/',$_REQUEST['url'])
this s the code i am using
Thanks for the help
artemis
08-29-2007, 11:59 AM
A quick tip, you have done:
preg_match('/[^a-zA-Z0-9]/',$_REQUEST['url'])
Which is fine, except there is no need for the a-zA-Z.
If you look at my version you will see there is the 'i' flag at the end:
preg_match('/[^a-z0-9]/i',$_REQUEST['url'])
Which means it does a case-insensitive search so it will match the upper case characters as well
salim
08-29-2007, 12:07 PM
yep i understood it.
But i just posted my code.(just like that).
Once again i thank you for the help
NogDog
08-29-2007, 07:43 PM
A bit faster will be:
if(!ctype_alnum($_REQUEST['url']))
{
// invalid input
}