Hi there…
I really need help with my ugly regex code because it still can’t diferrentiate string and string contain only numbers ok here the scenario;
All the string must meet this 3 conditions
1.String contain only alpha,space and dot
2.String contain only alphanumeric,space and dot
3.String contain only numbers
so here’s my attempt code so far
$testStringArray = array("abc. bc. def83","abc. bc.","123","567","fdg. qwe.","dfg. rtu. hu8");
//so i start filter testing here
$total = count($testStringArray);
for($i=0;$i<$total;$i++){
if(preg_match('/[a-zA-Z.\\...\\\\s.]+$/',$testStringArray[$i])){
echo $i." : ".$testStringArray[$i]." contain only alpha,dot,space";
}else if(preg_match('/^[a-zA-Z0-9.\\...\\\\s.]+$/i/',$testStringArray[$i])){
echo $i." : ".$testStringArray[$i]." contain only alpha,dot,numbers,space";
}else if(preg_match('/^[0-9]/',$testStringArray[$i])){
echo $i." : ".$testStringArray[$i]." contain only numbers";
}
}
Current output:
contain only alpha,dot,numbers,space
contain only alpha,dot,space
contain only alpha,dot,numbers,space–>it seems the regex not wokr here
contain only alpha,dot,numbers,space–>it seems the regex not wokr here
contain only alpha,dot,space
contain only alpha,dot,numbers,space
suppose to :
contain only alpha,dot,numbers,space
contain only alpha,dot,space
contain only numbers—>shoud be numbers only
contain only numbers—>shoud be numbers only
contain only alpha,dot,space
contain only alpha,dot,numbers,space
So i really need help with it…thanks in advance guys…