I've been looking at the file MicrosoftMvcJQueryValidation.js
which is the layer between your page and the jquery.validate
object in ASP.NET MVC 2 Beta.
It will allow any type of validation rule supported by jquery.validate and had additional special handling for regularexpressions, strings, ranges and required fields. If it is a generic/unknown rule type it will just pass through the parameters like this :
default:
__MVC_ApplyValidator_Unknown(rulesObj,
thisRule.ValidationType, thisRule.ValidationParameters);
break;
However - I cannot seem to figure out how to inject additional rules into the JSON that is generated by the framework, such as 'email'. Normally the rules just come from the attributes such as [Required]
.
I know there are lots of extensivbility points to replace the whole validation metadata provider - but I'm looking for a simple way.
How can I use - for instance the 'email' or 'creditcard' validators in conjunction with a simple model like this:
public class LoginDetails { public bool Editable { get; set; }
[Required(ErrorMessage="Please enter your email")]
public string Username { get; set; }
[Required(ErrorMessage="Please enter your password")]
public string Password { get; set; }
}