Mvc Validation Regex Attribute Works In C# But Not Javascript
I'm attempting to do validation on form fields via MVCs regular expression attributes. But it seems that no matter what regular expression I use, the validation only works on the s
Solution 1:
On your model:
[RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,4}\.[0-9]{1,4}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "invalid.")]
and make sure jquery.validate.min.js and jquery.validate.unobtrusive.min.js are referenced in your page
and finally in your web.config
<add key="ClientValidationEnabled"value="true" />
<add key="UnobtrusiveJavaScriptEnabled"value="true" />
Or if you want to do it using JS:
^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,4}\.[0-9]{1,4}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
Solution 2:
Apparently this is a currently known bug in the version of KendoUI i was using. Im not sure if there is an applicable update for it yet. More information about it here, http://www.kendoui.com/forums/mvc/general-discussions/regular-expression-validator-not-working-in-grid-popup.aspx
Post a Comment for "Mvc Validation Regex Attribute Works In C# But Not Javascript"