php验证码数字
I've inherited a lot of code where the previous developer used PHP's is_numeric() and it's gotten them into trouble. There's a big difference between validating that a value is numeric and validating that a value is all digits. Here's how to validate the two:
我继承了很多代码,以前的开发人员在其中使用了PHP的is_numeric() ,这使他们陷入了麻烦。 验证值是数字与验证值是全数字之间有很大的区别。 验证这两种方法的方法如下:
/* numeric, decimal passes */function validate_numeric($variable) { return is_numeric($variable);}/* digits only, no dots */function is_digits($element) { return !preg_match ("/[^0-9]/", $element);}
A customer number, for example, should not have any decimal points but using is_numeric() would let a decimal value pass the test. Don't be this guy!
例如,客户编号不应包含任何小数点,但是使用is_numeric()可以让十进制值通过测试。 不要成为这个人!
翻译自:
php验证码数字