ExpressiveAnnotations - annotation-based conditional validation

 
Usage sample for model validation in ASP.NET MVC
change language to test localized information: polski [english]
disable or enable client-side validation: [client] server
annotate required fields using: [asterisks] asterisks-with-hiding no-annotating
  1. [Required]
    
    [show attribute]
  2. [RequiredIf("GoAbroad == true")]
    
    [show attribute]
  3. [RequiredIf("Identification == Document.ID"]
    [RequiredIf("Identification == Document.Passport"]
    [AssertThat("Identification == Document.ID ? IsRegexMatch(IdentificationValue, '^[a-zA-Z]{3}[0-9]{6}$') : true"]
    [AssertThat("Identification == Document.Passport ? IsRegexMatch(IdentificationValue, '^[a-zA-Z]{2}[0-9]{7}$') : true"]
    
    [show attribute]
  4. [Required]
    [AssertThat("Country != NextCountry ? StringArrayLength(KnownLanguages) > 1 : true")]
    [ValueParser("ArrayParser")]
    
    [show attribute]
  5. [RequiredIf(@"GoAbroad == true
                  && (
                         (NextCountry != 'Other' && NextCountry == Country)
                         || (Age > 24 && 55 ≥ Age)
                     )")]
    [RequiredIf("IntArrayContains(Age, [15, 16, 17])")] 
    [AssertThat(@"ReasonForTravel != 'John\'s cat named ""\\\'""\n (Backslash Quote)' && ReasonForTravel != SIMONS_CAT")]
    
    [show attribute]
  6. [RequiredIf("GoAbroad == true")]
    [AssertThat("ReturnDate >= Today()", Priority = 1)]
    [AssertThat("ReturnDate >= Today() + WeekPeriod", Priority = 2)]
    [AssertThat("ReturnDate < AddYears(Today(), 1)")]
    [ValueParser("NonStandardDateParser")]
    
    [show attribute]
    Latest suggested return: 12/18/2018
  7. [RequiredIf("GoAbroad == true && ReturnDate > LatestSuggestedReturnDate", AllowEmptyStrings = true)]
    
    [show attribute]
  8. [RequiredIf("GoAbroad == true")]
    
    [show attribute]
  9. [AssertThat("(PoliticalStability == Stability.Low || PoliticalStability == Stability.Uncertain) ? AwareOfTheRisks == true : true")]
    
    [show attribute]
  10. [RequiredIf("SportType == 'Extreme' || (SportType != 'None' && GoAbroad == true)")]
    [AssertThat("IsBloodType(Trim(BloodType))"]
    
    [show attribute]
    1. [RequiredIf("Parent.GoAbroad && Phone == null")]
      [AssertThat("IsEmail(Email)")]
      
      [show attribute]
    2. [RequiredIf("Parent.GoAbroad && Email == null")]
      [AssertThat(@"IsRegexMatch(Phone, '^\\d+$'), Priority = 1")]
      [AssertThat("Length(Phone) > 8 && Length(Phone) < 16", Priority = 2)]
      
      [show attribute]
    3. [AssertThat("StartsWith(Details, StreetPrefix)")]
      [AssertThat("Length(Trim(Details)) > Length(StreetPrefix) + 1")]
      
      [show attribute]
    4. [AssertThat("StartsWith(Details, StreetPrefix)")]
      [AssertThat("Length(Trim(Details)) > Length(StreetPrefix) + 1")]
      
      [show attribute]
  11. [AssertThat("AgreeForContact == true")]
    
    [show attribute]
  12. [RequiredIf(@"AgreeForContact == true
                  && (ContactDetails.Email != null || ContactDetails.Phone != null)
                  && (ContactDetails.Addresses[0].Details != null || ContactDetails.Addresses[1].Details != null))]
    
    [show attribute]
  13. [AssertThat("FlightId != Guid('00000000-0000-0000-0000-000000000000') || !GoAbroad")]
    
    [show attribute]
  14. [RequiredIf("GoAbroad == true")]
    [AssertThat("GoAbroad
                     ? IntArrayLength(SelectedDonations) > 2
                     : IntArrayLength(SelectedDonations) > 1", Priority = 1)]
    [AssertThat("SelectedDonations != null && IntArrayLength(SelectedDonations) > 0 
                     ? SelectedCurrencies[0] || SelectedCurrencies[1]
                     : true", Priority = 2")]
    [ValueParser("ArrayParser")]
    
    [show attribute]
                    Bitcoin Ethereum
  15. [CustomRequiredIf("GoAbroad == true")]
    [CustomAssertThat("Length(コメント) > 1e1 - 1", Priority = 2)]
    [CustomAssertThat("Length(コメント) > 1e1 - 6", Priority = 1)]
    
    [show attribute]