srkirkland/DataAnnotationsExtensions — pull request #43 by justinsa (2012-06-07 08:12:18+00:00)
Title: RequiredHttpAttribute and some regular expressions

Let me know if I should change anything or if this isn't of interest to the project. I needed these for my own project and figured they might be useful to others.

Add: RequiredHttpAttribute.cs - provides same functionality as RequiredAttribute.cs and extends it with an optional parameter to only validate on particular HTTP methods. This is extremely useful when designing a controller that handles a REST interface as the Create and Update methods should use the same model but may have different Required fields. This behaves identically to Require if no HttpMethod is specified. Usage: [RequiredHttp(HttpMethod = "POST")].

Add: Regular expressions for currency codes, country codes, and culture codes - these validate structural correctness based on ISO 4217, RFC 4646, ISO 1366, and ISO 639. These do not validate existence.

Add: Regular expression for phone numbers - this is a reasonable general purpose phone number regular expression. It allows for a large number of incorrect formats but it ensures only digits are entered and that non-digit characters show up in permitted places and matching in the case of parenthesis. This is a good first line of validation to catch nonsense or typos.