【发布时间】:2012-05-30 05:49:41
【问题描述】:
我需要在 php 上使用正则表达式验证 unix 时间。 示例:
<?php
is_unix( $unix )
{
if( preg_match( '/([0-9]+)/' , $unix ) )
{
return true;
}
return false;
}
?>
谢谢 ;)
【问题讨论】:
-
任何介于零和
time()产生的数字都是有效的 -
您的 RegEx 仅检查变量中是否至少出现一个数字。要检查整个值,您可以使用
/^\d+$/(以确保它从字符串的开头检查到结尾)或将值转换为 int 并检查两者是否相等:(int)$unix == $unix
标签: php regex validation preg-match