我有jQuery个验证库用于申请,但当我在提交前验证不起作用.当判断下面该文件的第1行所述元素时,需要一些帮助.

//jQuery表单验证 /** *@au:Gcobani Mkontwana @日期:04/03/2023 @Return错误验证消息. *函数在申请贷款前对用户进行验证. 对于质量判断,字段是非常必填的. */

`
$(function (){
$("#personalloan").validate({
    rules: {
        firstName:{
            requuire:true
        },
        lastName:{
            require:true
        },
        idnumber:{
            require:true,
            minlength:13
        },
        cellno:{
            require:true,
            minlength:10
        },
        email:{
            require:true,
            email:true
        },
        employmentStatus: {
            require:true
        },
        salaryPaymentFrequency: {
            require:true
        },
        payslip: {
            require:true
        },
        consent: {
            require:true,
            consent:true
        },
        terms: {
            require:true,
            terms:true
        }
    },
    messages: {
        firstName:"This field is mandatory",
        lastName:"This field is mandatory",
        idnumber:"This field is mandatory",
        cellno:"This field is mandatory",
        email:"This field is mandatory",
        employmentStatus:"This field is mandatory",
        salaryPaymentFrequency:"This field is mandatory",
        payslip:"This field is mandatory",
        consent:"This field is mandatory",
        terms:"This field is mandatory"
    
    }

});


});

// HTML form application
<form id="personalloan" action="qualify.php" method="post" >
                    <label for="firstName">First name:</label><br>
                    <input type="text" id="firstName" name="firstName"><br>
                    <label for="lastName">Last name:</label><br>
                    <input type="text" id="lastName" name="lastName" ><br>
                    <label for="idnumber"> ID Number:</label><br>
                    <input type="text" id="idnumber" name="idnumber"><br>
                    <label for="cellno"> Cellphone Number:</label><br>
                    <input type="text" id="cellno" name="cellno"><br>
                    <br>
                     <label for="email"> Email:</label><br>
                    <input type="text" id="email" name="email"><br>
                    <br>
                    <label for="employmentStatus">Employment Status:</label><br>
                    <select name="employmentStatus" id="employmentStatus">
                        <option value="">Choose an option </option>
                        <option value="Permanently employment for a period of three months">Permanently employment for a period of three months </option>
                        <option value="Short term contract for a period of three months">Short term contract for a period of three months</option>
                        <option value="Other">Other</option>
                    </select><br>
                    <br>
                    <label for="salaryPaymentFrequency">Salary Payment Frequency:</label><br>
                    <input type="text" id="salaryPaymentFrequency" name="salaryPaymentFrequency"><br>
                    Do you have a payslip?<br>
                    <input type="radio" id="payslip" name="payslip" value="YES">
                    <label for="YES">YES</label>
                    <input type="radio" id="payslip" name="payslip" value="NO">
                    <label for="NO">NO</label><br>
                    Do you consent to give us doing a credit check?<br>
                    <input type="radio" id="consent" name="consent" value="YES">
                    <label for="YES">YES</label>
                    <input type="radio" id="consent" name="consent" value="NO">
                    <label for="NO">NO</label><br>
                    <br>
                    <input type="checkbox" id="terms" name="terms" value="YES">
                    <label for="terms">I accept the <a href="doc/Website Terms and Conditions Policy and Procedure (ACI).pdf"> T's and C's.</a></label><br>
                    <input type="checkbox" id="personalinfo" name="personalinfo" value="YES">
                    <label for="personalinfo"> I give consent to my personal information being shared with a selected third party in order for them to contact me.</label><br>
                    <br>
                    <input type="submit" value="Submit">
                    </form>
            </div>
        </div>`

推荐答案

按照以下建议:

https://stackoverflow.com/tags/jquery-validate/info

我添加了一个ready方法.

将所有require个属性更改为required,firstName中有一个拼写错误,添加一个指向validate.js库的脚本链接

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.js"></script>

而且它起作用了.

$(document).ready(function() { 
$("#personalloan").validate({
    rules: {
        firstName:{
            required:true
        },
        lastName:{
            required:true
        },
        idnumber:{
            required:true,
            minlength:13
        },
        cellno:{
            required:true,
            minlength:10
        },
        email:{
            required:true,
            email:true
        },
        employmentStatus: {
            required:true
        },
        salaryPaymentFrequency: {
            required:true
        },
        payslip: {
            required:true
        },
        consent: {
            required:true,
            consent:true
        },
        terms: {
            required:true,
            terms:true
        }
    },
    messages: {
        firstName:"This field is mandatory",
        lastName:"This field is mandatory",
        idnumber:"This field is mandatory",
        cellno:"This field is mandatory",
        email:"This field is mandatory",
        employmentStatus:"This field is mandatory",
        salaryPaymentFrequency:"This field is mandatory",
        payslip:"This field is mandatory",
        consent:"This field is mandatory",
        terms:"This field is mandatory"
    
    }
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.js"></script>

<form id="personalloan" action="qualify.php" method="post" >
                    <label for="firstName">First name:</label><br>
                    <input type="text" id="firstName" name="firstName"><br>
                    <label for="lastName">Last name:</label><br>
                    <input type="text" id="lastName" name="lastName" ><br>
                    <label for="idnumber"> ID Number:</label><br>
                    <input type="text" id="idnumber" name="idnumber"><br>
                    <label for="cellno"> Cellphone Number:</label><br>
                    <input type="text" id="cellno" name="cellno"><br>
                    <br>
                     <label for="email"> Email:</label><br>
                    <input type="text" id="email" name="email"><br>
                    <br>
                    <label for="employmentStatus">Employment Status:</label><br>
                    <select name="employmentStatus" id="employmentStatus">
                        <option value="">Choose an option </option>
                        <option value="Permanently employment for a period of three months">Permanently employment for a period of three months </option>
                        <option value="Short term contract for a period of three months">Short term contract for a period of three months</option>
                        <option value="Other">Other</option>
                    </select><br>
                    <br>
                    <label for="salaryPaymentFrequency">Salary Payment Frequency:</label><br>
                    <input type="text" id="salaryPaymentFrequency" name="salaryPaymentFrequency"><br>
                    Do you have a payslip?<br>
                    <input type="radio" id="payslip" name="payslip" value="YES">
                    <label for="YES">YES</label>
                    <input type="radio" id="payslip" name="payslip" value="NO">
                    <label for="NO">NO</label><br>
                    Do you consent to give us doing a credit check?<br>
                    <input type="radio" id="consent" name="consent" value="YES">
                    <label for="YES">YES</label>
                    <input type="radio" id="consent" name="consent" value="NO">
                    <label for="NO">NO</label><br>
                    <br>
                    <input type="checkbox" id="terms" name="terms" value="YES">
                    <label for="terms">I accept the <a href="doc/Website Terms and Conditions Policy and Procedure (ACI).pdf"> T's and C's.</a></label><br>
                    <input type="checkbox" id="personalinfo" name="personalinfo" value="YES">
                    <label for="personalinfo"> I give consent to my personal information being shared with a selected third party in order for them to contact me.</label><br>
                    <br>
                    <input type="submit" value="Submit">
                    </form>
            </div>
        </div>

Html相关问答推荐

CSS/添加margin—top到嵌入式facebook帖子

网格容器中的定心元件

SVG';COLOR&39;属性不优先于通用css';COLOR&39;属性

如何在ASP.NET Core中添加换行符

为什么带有截断的 contentedible div 在受约束时会在 Chrome 中添加空格

使用 popover api 和 `

如何使Bootstrap 5卡可点击

如何使用javascript在jsx中重复插入特殊字符?

Tailwind 网格行高度可防止拉伸到最高行的所有相同高度

如何为Vuetify输入控件减小标签和字段之间的间距?

模拟另一个输入值设置表单输入的数值

如何只为 Navbar 中的一个元素提供动画,其余元素没有使用 css 的动画

带有伪元素的不规则形状的渐变边框

将表格标题和过滤器调整到表格的顶部边缘

如何在 blazor 中单击单个按钮调用 2 个等待任务

需要禁用聚焦输入的工具提示(jquery)

为什么相同持续时间的转换需要不同的时间?

辅助功能:alt 或 alt="" 用于装饰图像

绝对定位的 div 与另一个静态定位的 div 的边距顶部一起移动

我正在try 向我预先存在的导航栏添加响应式汉堡包导航,但由于某种原因它没有显示