如何在PHP上使用RegExp验证unix时间?
可能重复:如何在PHP上使用RegExp验证unix时间?,php,regex,validation,preg-match,Php,Regex,Validation,Preg Match,可能重复: 我需要在php上用regexp验证unix时间。 例如: 谢谢;) 那么: function is_unix($t) { if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) { return
我需要在php上用regexp验证unix时间。 例如:
谢谢;) 那么:
function is_unix($t) {
if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) {
return true;
}else{
return false;
}
函数是unix($t){
if(is numeric($t)&&0零和time()
产生的任何数字之间的任何数字都是有效的。您的正则表达式只检查变量中是否至少有一个数字出现。要检查整个值,您可以使用/^\d+$/
(确保它从字符串开始检查到结束)或者将该值转换为一个int,然后检查两者是否相等:(int)$unix==$unix
替换您不希望该值超过的某个日期?@Mark:谢谢,我在中添加了该位。
function is_unix($t) {
if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) {
return true;
}else{
return false;
}