检查空输入表格

时间:2015-08-12 07:37:37

标签: php regex

如何通过filter_var()

提交时检查空输入表单

我想使用 filter_validate_regexp 功能,但不知道正则表达式模式来检查空字段。

$cond = filter_var(
    $_GET['name'],
    FILTER_VALIDATE_REGEXP,  
    array(
        'options' => array('regexp'=>'???')
    )
) ? true : false;  

2 个答案:

答案 0 :(得分:1)

为了检查某个值是否为空,猜猜你的意思是有一个值,只有if会这样做。

if ($_GET['name'])

答案 1 :(得分:1)

Detect non-empty string with regexp?

/[\s\S]/

这就是你要找的东西吗?

编辑:

$_GET['name'] == null --> $cond = false
$_GET['name'] == false --> $cond = false
$_GET['name'] == true --> $cond = true
$_GET['name'] == '' --> $cond = false
$_GET['name'] == ' ' --> $cond = true
$_GET['name'] == 'anystring' --> $cond = true
相关问题