-2

I'm current working on jquery and have a problem about the validation usage. I made a code for register but when i run it, nothing happened and there's no error show up, either. can anyone help me with that?

 <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" ></script>
    <script type="text/javascript" scr="js/signup-form.js"></script>
    <script>
        $().ready(function () {
            $("#registerForm").validate({
                rules: {
                    email: {
                        required: true,
                        email: true
                    },
                    userName: {
                        required: true,
                        minLength: 8
                    },
                    password: {
                        required: true,
                        minlength: 8
                    },
                    passwordConfirmation: {
                        required: true,
                        equalTo: "#password"
                    }
                },
                messages: {
                    email: {
                        required: "This field can not be empty",
                        email: "Email address does not valid"
                    },
                    userName: {
                        required: "This field can not be empty",
                        minLength: "UserName must contain at least 8 charactors"
                    },
                    password: {
                        required: "This field can not be empty",
                        minLength: "Password must contain at least 8 charactors"
                    },
                    passwordConfirmation: {
                        required: "This field can not be empty",
                        equalTo: "Please enter the same password above"
                    }
                }

            });

        });

    </script>
    <form id="registerForm">
        <fieldset>
            <div>
                <p>
                    <label>Email</label>
                    <input type="email" value="@Model.Email" name="email" id="email" />


                </p>
                <p>
                    <label>Username</label>
                    <input tyep="text" value="@Model.UserName" name="username"/>


                </p>
                <p>
                    <label>Password</label>
                    <input type="password" value="@Model.Password" name="password"/>

                </p>
                <p>
                    <label>Confirm Password</label>
                    <input type="password" value="@Model.PasswordConfirmation" name="passwordConfirmation" />

                </p>

            </div>
        </fieldset>
        <p>
            <input type="submit" vaule="Register" />
        </p>
    </form>

when i hit the register button, nothing happened and there's no error. can anyone help me out with that?
by the way, i using visual studio MVC 5, does that make any problem? thanks!!!

@edit:
i have tried my code at hjsfiddle.net/5d1b50k6 and it works fine. but it still not working in my computer. does mvc would affect that??

10
  • The code you've presented to us is working fine: jsfiddle.net/5d1b50k6 Commented Feb 16, 2015 at 20:57
  • $().ready(...) should be $(document).ready(...); and you've misspelled minlength as minLength. Commented Feb 16, 2015 at 20:58
  • @Sparky i tried that early, it not work either. but thanks for correcting the mistake. Commented Feb 16, 2015 at 22:16
  • @Sparky so do you think my mvc might be the problem?? i am using visual studio Commented Feb 16, 2015 at 22:20
  • I don't use Visual Studio as I prefer to have more control over my code. Do you know how to use it? Are you using the unobtrusive-validation plugin? If so, that would be taking precedence over your .validate() method. Commented Feb 16, 2015 at 22:28

1 Answer 1

0

On line 6, add # to select the ID:

$("#registerForm").validate({

http://api.jquery.com/id-selector/

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for catching that mistake. but it still not working and have no error showing up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.