+
81
-

php验证整数或小数点的正则表达式问题

php

今天在网上找了个验证整数和小数点的正则,有问题,大家帮我看看

// $accountPrice = $_GET['num'];
// $accountPrice = 111;
// $accountPrice = 1112.;
// $accountPrice = 2324.1;
// $accountPrice = 2324.15;
// $accountPrice = 2324.157;//wrong
// $accountPrice = 0.57;
 
 
if (preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $accountPrice)) {
	echo '整数或小数二位的正则';
}else{
    echo '错';
}


网友回复

我知道答案,我要回答