hi all..i need some help with php code i have this code $ValResult=0; preg_match_all('/^[a-zA-Z- .,]{2,200}$/', $Valstring, $matches); foreach($matches[0] as $value){ if($value!='' || $value!='0' || $value!='null'){ $ValResult=1; } else{ $ValResult=0; } } return $ValResult; Code (markup): and try it with 1)$Valstring='hulu'; and its return $ValResult=1--ok 2)$Valstring='hulu-'; and its return $ValResult=1--ok 3)$Valstring='hulu123'; and its return $ValResult=0--ok 4)$Valstring='hulu]'; and its return $ValResult=0--ok but the when i try it with 5)$Valstring='hulu+'; and its return $ValResult=1--not ok it suppose to return $ValResult=0 can someone help me with..thanking you all in advance for reviewing my post
Include a literal '+' sign in your preg Notice that I have put a backslash before that '+' sign, its because I don't want to confuse PHP whether it is a pattern modifier. $pattern='/^[a-zA-Z- .,\+]{2,200}$/' PHP:
By any chance is $ValString coming from $_GET or somewhere else where a plus symbol is synonymous with a space, after being urldecoded ? I see your pattern allows for spaces.
<? $Valstring = "hulu+"; $ValResult=0; preg_match_all('/^[a-zA-Z- .,]{2,200}$/', $Valstring, $matches); foreach($matches[0] as $value){ if($value!='' || $value!='0' || $value!='null'){ $ValResult=1; } else{ $ValResult=0; } } print $ValResult; ?> this way i am getting result as 0.May be u r getting the value of $Valstring from somewhere else that can change the meaning of + .