// 限制$string中只能包含大于0的数字和英文逗号,用正则表达式验证。
class regx {
public static function check($str) {
if(preg_match("/^([1-9,])+$/",$str)) {
return true;
}
return false;
}
}
$str = "12345,6";
if(regx::check($str)) {
echo "success";
}else{
echo "fail";
}
本文介绍了一个使用正则表达式来验证字符串是否只包含大于0的数字和英文逗号的方法。通过PHP代码实现,展示了如何定义和使用正则表达式进行数据格式检查。
1266

被折叠的 条评论
为什么被折叠?



