尝试验证时,Jquery验证无效

时间:2015-03-16 05:05:33

标签: jquery jquery-validate

当我尝试执行时,此验证无效。我的问题是使用Jquery验证我的表单。我的验证仅适用于验证功能,但后来我添加了提交选项并且未进行验证。我想验证我的表单,然后执行提交。

<script type="text/javascript">
      $().ready(function() {

                //form validation rules
                $("#myForm").validate({
                    rules: {
                        seae: "required",
                        brand: "required",
                        territory:"required",
                        name: {
                            required:true,
                            minlength:2
                        },
                        number: "required",

                        email: {
                            required: true,
                            email: true
                        },
                        contact: {
                            required: true,
                            matches:"([0-9]{10})|(\([0-9]{3}\)\s+[0-9]{3}\-[0-9]{4})",
                            minlength:10,
                            maxlength:10
                        }

                    },
                    messages: {
                        seae: "Please select whether the employee is SE or AE",
                        brand: "Please select the brand",
                        territory: "please select the territory",
                        name: {
                            required: "Please provide a name",
                            minlength: "Please enter the valid name"
                        },
                        e_id: "please provide the employee id",
                        email: "Please enter a valid email address",
                        contact: {
                            required:"please provide the contact number of the employee",
                            matches:"please provide the valid contact number"
                        }
                    },
                    submitHandler: function(form) {
                        form.submit();
                    }
                });
      });

    <form id="myForm" name="myForm" action='insert.php' method='post' >
    <input type='hidden' name='st' value=0>


    <table  style="text-align:center; width:100%">
    <tr><td style="text-align:right"><label>Select SE/AE:</label></td><td style="text-align:left"> <select name='seae' id='s1' onchange=ajaxFunction('s1');>
            <option>Select One</option>
    <?php
    //require "../include/z_db1.php";
    require "configs.php";// connection to database
    $sql="select distinct seae from se_ae ";
    foreach ($dbo->query($sql) as $row) {
    echo "<option value=$row[seae]>$row[seae]</option>";
    }
    ?>
    </select></td></tr>
    <tr><td style="text-align:right"><label>Select brand:</label></td><td style="text-align:left"> <select name='brand'  onchange=ajaxFunction('s2');>
    <option value=''>Select One</option></select></td></tr>

    <tr><td style="text-align:right"><label>Select territory:</label></td><td style="text-align:left"> <select name='territory'   onchange=ajaxFunction('s3');>
    <option value=''>Select One</option></select> </td></tr>

    <tr><td style="text-align:right"><label for="name">Employee Name:</label></td>
        <td style="text-align:left"><input type="text" id="name" name="name"  /></td></tr>

    <tr><td style="text-align:right"><label for="number">Employee ID:</label></td>
        <td style="text-align:left"><input type="text" id="number" name="number"  /></td></tr>

        <tr><td style="text-align:right"><label for="email"> Email:</label></td>
        <td style="text-align:left"><input type="text" id="email" name="email"  /></td></tr>

        <tr><td style="text-align:right"><label for="name"> Contact:</label></td>
        <td style="text-align:left"><input type="text" id="contact" name="contact"  /></td></tr>

    <tr><td style="text-align:right" class='swMntTopMenu'><input style="background-color:#F3E00D"  name="Reset" type="reset" value="RESET"></td>
    <td style="text-align:left" class='swMntTopMenu'><input style="background-color:#F3E00D"  name="submit" type="submit" value="CREATE"></td></tr>
    </table>

    </form>

0 个答案:

没有答案