来自不同国家的邮政编码验证

问题描述

在这样的网站上进行了验证检查

'username' => array('required' => true,'min' => 2,'max' => 50,'unique' => 'users'),

因此需要用户名用户名最少2个,最多50个字符,并且在“用户”表中唯一。

我想添加邮政编码。问题是,它因国家/地区而异。该国家处于选择状态:

<select class="select" name="land" id="land" onchange="if (this.selectedindex) land();">
  <option value="-1">--</option>
  <option value="c1">Country 1</option>
  <option value="c2">Country 2</option>
  <option value="c3">Country 3</option>
</select>

在JS代码中,我有这个:

function land(){
    
    $("select.land").change(function() {
        var selectedCountry = $(this).children("option:selected").val();
        if(selectedCountry === 'Belgie'){
            <?PHP $postalCode = "'postcode' => array('required' => true,'figures' => true,'max' => 4,'notlowercase' => true,'notuppercase' => true,'notspecial' => true)," ?>
        }else if(selectedCountry === 'Nederland'){
            <?PHP $postalCode = "'postcode' => array('required' => true,'max' => 7,'uppercase' => true," ?>
        }
    });
}

问题是,如果我仅在验证中输入$ postalCode,就像这样:

'username' => array('required' => true,$postalCode,...

然后PHP在foreach上给了我一个无效的参数,它的开头是这样的:

foreach($rules as $rule => $rule_value) {

问题是,我该如何解决

--------更新----------- 现在我有了这个:

$land = $_POST['land']; 
if($land === 'Belgie' || $land === 'belgie'){ 
  $test = "'postcode' => array('required' => true,"; 
}else if($land === 'Nederland' || $land === 'nederland'){ 
  $test = "'postcode' => array('required' => true,'max' => 6,"; 
} 

但仍然是相同的错误(参数无效)。我认为这是因为我提供了一个String并且期望使用Array,但不知道如何解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)