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; }

    }
2
  • Use dataannotations Commented Feb 4, 2013 at 15:08
  • Can't use dataannotations because there are dynamic controls. Commented Feb 4, 2013 at 15:21

1 Answer 1

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.

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

3 Comments

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..
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)
Thank you for pointing me to the right direction, I saw this: stackoverflow.com/questions/8084374/…

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.