如何添加其他更复杂的验证详细信息



如果我还想验证邮政编码字段中只有 5 位数字,并且至少有 10 位数字没有除 (( 或 - 以外的字母在电话号码字段中,我将如何将其添加到此代码中?谢谢!

 if (jQuery('#first_name').val() !== '' && jQuery('#last_name').val() !== '' && jQuery('#zip_code').val() !== '' && jQuery('#phone_number').val() !== '')  {
        jQuery(".home_step_two .next_incomplete").hide();
        jQuery(".home_step_two .next").show();
    } else {
        jQuery(".home_step_two .next").hide();
        jQuery(".home_step_two .next_incomplete").show();
    }
zipCodeRight=()=>parseInt(jQuery('#zip_code').val(),10) && jQuery("#zip_code").val().length== 5;
phoneNumberRight=()=>jQuery("#phone_number").val().length>10&& jQuery("#phone_number").val().split("").every(el=>"0123456789-+()".split("").indexOf(el)+1);
if(zipCodeRight() && phoneNumberRight()){
  alert("allright");
}

只需检查邮政编码是否可以转换为数字,其长度是否为 5,以及电话号码是否仅包含"0123456789((+-"......

最新更新