请记住,使用没有 preg_match 的 if 语句验证有效,但使用 preg_match 它总是返回 false
我想验证该字段并确保它里面有 8 个数字,不多不少。
function account_number_validation($validation_result){
$form = $validation_result["form"];
if(!preg_match('[0-9]{8}', $_POST['input_19'])){
// set the form validation to false
$validation_result["is_valid"] = false;
//finding Field with ID of 1 and marking it as failed validation
foreach($form["fields"] as &$field){
if($field["id"] == "19"){
$field["failed_validation"] = true;
$field["validation_message"] = "This field is invalid!";
break;
}
}
}
//Assign modified $form object back to the validation result
$validation_result["form"] = $form;
return $validation_result;
}
有什么想法吗?