1

can someone please tell me how to write validation for "first name and last name must not match".

my model code is

public string firstname{get; set;}
public string lastname{get; set;}

Can we use 'compare' attribute to compare these values

  • possible duplicate of [How to create a Must Not Match attribute for email address](http://stackoverflow.com/questions/10783390/how-to-create-a-must-not-match-attribute-for-email-address) – DavidG Jul 24 '14 at 14:47
  • I'd say it's a duplicate of this one: http://stackoverflow.com/questions/8786251/opposite-of-compare-data-annotation-in-net – Termato Jul 24 '14 at 15:10

1 Answers1

0

You can do something like this

[NotEqualTo("lastname")]
public string firstname{ get; set; }
public string lastname{get; set;}

References: THE COMPLETE GUIDE TO VALIDATION IN ASP.NET MVC 3 - PART 2 and StackOverflow Solution

The StackOverflow link has a lot more types of annotations that could be useful. Hope this helps!

Community
  • 1
  • 1
Termato
  • 1,556
  • 1
  • 16
  • 33