Regular Expression Validator HtmlHelper for ASP .Net MVC

Sometimes, it is useful to use regular expressions for validations. The Regular Expression Validator HtmlHelper is designed to help developers accomplish this. This Helper is useful if you want to perform server side operations (like fetching the Regular Expression and Error Message from a database or resource files) and want the validation part to be client-side using the JQuery validaton plugin.

Implementation

The Regular Expression Validator is an HtmlHelper built using Extension Methods.

If AutoWireupValidateOnSubmit is set to false, then Handler and the call to JQuery validate has to be done manually in the page. This is useful if it required to plug the Validator into an already existing validate call.

$(document).bind('submit', function () { $('form').validate({ rules: { FirstName: { FirstName: true }, LastName: { LastName: true }, UserID: { UserID: true } } });});In the rules section, the rule has to be called as shown above. The RuleName created by the helper is the same as the ControlID. The syntax is

The advantage of this validator is that it performs client-side validation using the JQuery validation plug-in.

This Helper is useful if you want to perform server-side operations (like fetching the Regular Expression and Error Message from a database or resource files) and want the validation part to be client-side using the JQuery validaton plugin.