asp.net mvc - custom validation attribute not working on client, just on server -


i trying implement custom attribute validation, similar 1 demonstrated here in scottgu's blog: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

i have custom validator attribute email:

public class emailattribute : regularexpressionattribute       {       public emailattribute() :                 base("^[a-za-z0-9](([_\\.\\-]?[a-za-z0-9]+)*)@([a-za-z0-9]+)(([\\.\\-]?[a-za-z0-9]+)*)\\.([a-za-z]{2,})$") { }       } 

my class uses this:

    [required(errormessage = validationcim.msgobaveznopolje)]     [email(errormessage = validationcim.msgmailneispravan)]     [stringlength(validationcim.lensrednjepolje, errormessage = validationcim.msgsrednjepolje)]     public string mail { get; set; } 

and works on server side, model validated ok, , everything. client side validation not activate second attribute, works required, , works stringlength not email. have tried including both jquery , microsoft ajax scripts, there seems no difference.

in scottgu's blog, states custom validation if implemented should work without need add custom script.

any ideas please?

use iclientvalidatable in asp.net mvc 3:

 public class emailattribute : regularexpressionattribute, iclientvalidatable {     public emailattribute()       :base(@"^([a-za-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-za-z0-9\-]+\.)+))([a-za-z]{2,4}|[0-9]{1,3})$")     {      }      public system.collections.generic.ienumerable<modelclientvalidationrule> getclientvalidationrules(modelmetadata metadata, controllercontext context)     {       var rule = new modelclientvalidationregexrule(this.errormessagestring, base.pattern);       return new[] { rule };     }   } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -