-1

I have validation with metadatas in a asp mvc project.

I want to validate the metadatas in the client side with jquery.validate and jquery.validate.unobtrusive.

The problem is that the metadatas [Email], [Phone] or [Url] it's not validated in the client side, so it's only validated in the server side.

Is there some form of validating this metadatas in jquery.validate?

Is there somo form of adding custom validations in jquery.validate?

Thanks.

Albert Cortada
  • 737
  • 3
  • 10
  • 25

2 Answers2

0

Jquery Validator has an validation type remote. In Js,

    UserName: {                        //TODO Apply Unique Server Side Validation
        required: true,
        custUserName: true,
        maxlength: 100,
        remote: {
            url: user/IsUserNameAvailable,
            type: "post",
            data: {
                email: function () {
                    return $("[name=UserName]").val();
                }
            }
        }
    },

Sample Controller method.

public JsonResult IsUserNameAvailable(string username)
{
    return Json(WebUserModel.IsUserNameAvailable(username));
}
Shanker Paudel
  • 740
  • 1
  • 9
  • 21
-1

if you are using jquey.validate then below link has demo of it and

http://jquery.bassistance.de/validate/demo/

below is the example for that

$().ready(function() {
// validate the comment form when it is submitted
$("#yourForm").validate();

// validate signup form on keyup and submit
$("#yourForm").validate({
    rules: {
        firstname: "required",
        lastname: "required",
        username: {
            required: true,
            minlength: 2
        },
        password: {
            required: true,
            minlength: 5
        },
        confirm_password: {
            required: true,
            minlength: 5,
            equalTo: "#password"
        },
        email: {
            required: true,
            email: true
        }},
  • It's not the perfect answer, but guided me to the solution of my problem. This other answer helped mee too: [link]http://stackoverflow.com/a/8263736/2096139 – Albert Cortada Mar 06 '14 at 14:53
  • -1 for blindly cutting & pasting the source code of the demo without any understanding, changing the selectors so it's invalid, and leaving it incomplete. – Sparky Mar 06 '14 at 16:36