Search code examples
asp.net-mvc-3unobtrusive-validation

MVC 3 - Compare Attribute - Perform case insenstive comparision on Client side


In the page I'm developing I have a "Email" field and "ConfirmEmail" field. And the requirement is to have a case insensitive comparision.

I could create a custom attribute and extend the behaviour of 'Compare' attribute that is inbuilt. This works on the serverside.

But I was not able to achieve it on client side. I'm sure that we have to do some additional things to make the unobtrusive jquery to do a case insensitive comparision.


Solution

  • You can use the compare attribute in MVC 3...which is a built in solution...

        [Compare("Email",ErrorMessage="your error message")]
        public string ConfirmEmail { get; set; }
    

    Update: my bad probably I should have read your question better...anyways... for the unobtrusive way to work, after creating an attribute (the override version of Compare)... you need to do some javascript work for the unobtrusive client side validation to work...here is an example blog post unobtrusive client side validation with MVC 3 ...that does something similar to what I'm talking about...if you need further help...just ping back...I will be glad to help you with this...

    Here is a more relevant post...which also talks about creating a custom attribute... Creating Custom Validation Attribute (Server side and Client Side)

    Hope this helps...