商城首页欢迎来到中国正版软件门户

您的位置:首页 >thinkphp如何判断变量是否为数字

thinkphp如何判断变量是否为数字

  发布于2023-05-01 阅读(0)

扫一扫,手机访问

方法:1、用“protected 变量=array(array('your_variable','number','变量为数字'),)”判断;2、用“is_numeric(变量);preg_match('/^\\d+$/',变量)”判断。

本文操作环境:Windows10系统、ThinkPHP5 版、Dell G3电脑。

thinkphp如何判断变量是否为数字

1、如果要用模型的自动验证,在模型中添加:

protected $_validate = array(
    array('your_variable','number','变量应为纯数字!'),
 );

2、如果自行验证,可以用函数或正则表达式

is_numeric($your_variable);
preg_match('/^\\d+$/',$your_variable);
本文转载于:https://www.yisu.com/zixun/688150.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注