function my_preg($str){ if(preg_match("/^[,1-9]+$/",$str)) { return $str; } else{ return false; } } var_dump(my_preg('123,'));