0

I need the following validation on several input fields:

01 - Unicode String. No line breaks or tabs. DATA_MAX_LENGTH applies.
02 - Unicode Memo. Line breaks permitted. No tabs. DATA_MAX_LENGTH applies.
03 - Non-negative integer, as string.
04 - Non-negative Money (precision 18,2), as string.
05 - Date, as string, in the U.S. 4-digit-year format (e.g. 12/31/2012).
06 - Boolean (aka "Bit", "Yes/No"), as string, with "1" for True, "0" for False.

Is there a Jquery plugin that provide all these validation (or can be extended) or would using several plugin be a good idea. I am using MVC3 and I need them for dynamic controls on the form.

My model Question (these questions will be created for a dynamic quiz form):

public class Question
    {

        public int QuestionID { get; set; }
        public string QuestionText { get; set; }
        public Nullable<bool> Required { get; set; }
        public int DisplayOrder { get; set; }
        public int StepID { get; set; }
        public Nullable<int> DataType { get; set; }   // validation relate here (1-6)
        public Nullable<int> ControlType { get; set; }
        public string Choices { get; set; }
        public Nullable<int> MaxLength { get; set; }

    }
Chaka
  • 1,709
  • 11
  • 33
  • 58

1 Answers1

1

I'm personlly a big fan of Fluent Validation - it's a very powerful option that allows you to define validation rules using lambda syntax. See here for MVC integration info from the codeplex site and here for a blog post with great details on how to get it working with jQuery.

Redango
  • 26
  • 1
  • Would this work if each item needed a different validation..or would the validation be applied to the model only. Ex: if item one required money, item 2 required a date, item 3 required integer only, etc.. – Chaka Feb 04 '13 at 15:30
  • You can have a specific rule for each property of your model, or you can also create a custom rule that can be applied to more than one of the properties. As it's a fluent syntax you can also chain together multiple rules for a single property such as: RuleFor(customer => customer.Age).GreaterThan(18).LessThan(30) – Redango Feb 04 '13 at 15:39
  • Thank you for pointing me to the right direction, I saw this: http://stackoverflow.com/questions/8084374/conditional-validation-using-fluent-validation – Chaka Feb 04 '13 at 20:23