...

View Full Version : regular expression help



fractalbit
03-25-2004, 01:20 AM
Hello all,

can someone tell me how can i verify that a string contains only english characters and/or numbers? Nothing else is acceptable.

Thanks in advance.

raf
03-25-2004, 09:18 AM
What are english characters ?

fractalbit
03-25-2004, 03:22 PM
I want all the cahracters to be a-z, A-Z or 1-9. In other words i want the string to be an [[:alnum:]] . I want ALL the characters to be alnums. If any other character exists in the string (example @) i want the expression to return false. Please someone help me.

imaek
03-25-2004, 05:27 PM
this might not be the best way, but i think it will work;

<?
$string = "Whatever string here for validation";
if ( !eregi("^([A-Za-z0-9 ]+)$",$string) ) {
die("Not Valid.");
}
?>

fractalbit
03-25-2004, 06:37 PM
Thanks it worked! I somewhat modified your code :

$string = "fg34j29iaAArXfFGj92r";
$x = ereg("^([[:alnum:]]+)$", $string);

if($x){
print "VALID";
}else{
print "not valid";
}

Thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum