-4

我有一个注册表单,其中包含用 php 编写的表单中的一些字段要求,我正在尝试向其中添加一个验证插件,但该插件不起作用,我没有收到任何错误。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">

</script>                           

<script src="scripts/jquery.validate.js"></script>

<script>
$(function(){
$("#regForm").validate({
    rules: {
        brukernavn: {
            required: true,
            minlength:3,
            maxlength:10
        },
        passord: {
            required: true,
            minlength:3,
            maxlength:10
        },
        bekreft_pass: {
            required: true,
            minlength:3,
            maxlength:10
        },
        E_post: {
            required: true,
            email: true
        },
        bekreft_epost {
            required: true,
            email: true
        },
        messages: {


        }
    }
});

$.extend($.validator.messages, {
    required: "Obligatorisk felt:"
});
 });
</script>

 <form id="regForm" method="post" action="">
<label for="brukernavn">Brukernavn</label><br>
<input type='text' id="brukernavn" name="brukernavn"><br>

<label for="passord">Passord</label>
<input type="password" id="passord" name="passord"><br>

<label for="bekreft_pass">Bekreft passord</label>
<input type="password" id="bekreft_pass" name="passord2"><br>

<label for="E_post">E-post</label>
<input type="E-post" id="E_post" name="E-post"><br>

<label for="bekreft_epost">Bekreft e-post</label>
<input type="E-post" id="bekreft_epost" name="E-post2"><br>
<br>

<input type='submit' id"submit" value='Register'>

有谁看到问题出在哪里?

4

2 回答 2

1

这里缺少一个冒号:bekreft_epost {应该是bekreft_epost: {

此外,没有关闭表单标签。

于 2013-04-18T05:45:03.763 回答
1

messages不应低于rules

http://jsfiddle.net/samliew/uGsXC/10/

此外,验证规则名称必须匹配字段 NAME 属性而不是 ID:

http://jsfiddle.net/samliew/uGsXC/12/

于 2013-04-18T05:58:13.137 回答