Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe that your issue in case of <code>AlphaNumericAttribute</code> is that you did not added JavaScript adapter for your <code>alphanumeric</code> type of validator. </p> <p>You surely have somehting like this in your code:</p> <pre><code>$.validator.unobtrusive.adapters.add('ssn', function(options) { /*...*/ }); </code></pre> <p>Above code declares client side adapter for <code>SsnAttribute</code>. Note that it has name <code>ssn</code> which is the same as set in <code>ValidationType</code> property of <code>ModelClientValidationRule</code>.</p> <p>To fix issue with <code>AlphaNumericAttribute</code> you should return <code>ModelClientValidationRegexRule</code> as it is already has all necessary setup for your case (i.e. already existing adapter <code>regex</code>).</p> <pre><code>[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] public class AlphaNumericAttribute : RegularExpressionAttribute, IClientValidatable { public AlphaNumericAttribute() : base("^[-A-Za-z0-9]+$") { } public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { yield return new ModelClientValidationRegexRule(FormatErrorMessage(metadata.GetDisplayName()), Pattern); } } </code></pre> <p>But if there should be additional logic on client side behind the regex validation you should write and register your own unobtrusive adapter.</p> <p>To get the bigger image and for better undestanding of how custom validation could be implemented in ASP.NET MVC you can reffer to the blog post of Brad Wilson <a href="http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html">Unobtrusive Client Validation in ASP.NET MVC 3</a>, see <code>Custom adapters for unusual validators</code> section.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload