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.
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...
I'm not entirely certain what you are looking for as far as the Compare attribute, but for the JavaScript, this will do the comparison and you can take action from the client based on the results.
if (email.toUpperCase() == confirmEmail.toUpperCase()) {
alert("Emails are a match!");
} else {
alert("Emails do not match");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With