public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { //Check if Address2 is the same as Address1. If so show an error “Address2 cannot be the same as Address1” on Address2 field. //Check if State is 2 digits long. Otherwise show an error message “Enter a 2 digit State code”. //Check if Zipcode is 5 digits long. Otherwise show an error message “Enter a 5 digit Zipcode” if (Address1 == Address2 || Address2 == Address1) { yield return(new ValidationResult("Address2 cannot be the same as Address1")); } if (State.Length < 2 || State.Length > 2) { yield return(new ValidationResult("Please enter a 2 digit State")); } //Check if Zipcode is 5 digits long. Otherwise show an error message “Enter a 5 digit Zipcode” //if (Zipcode.Length > 5 || Zipcode.Length < 5) // { // yield return (new ValidationResult("Please enter a 5 digit zipcode")); // } if (Zipcode.Split(' ').Length > 5) { yield return(new ValidationResult("Your description is too verbose")); } //throw new NotImplementedException(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { // Validation 1 : Zip code has to be between if (Address2 == Address1) { yield return(new ValidationResult("Address2 cannot be same as Address 1")); } if (State != null && State.Split(' ').Length > 2) { yield return(new ValidationResult("Enter 2 digit State code ")); } if (Zipcode != null && Zipcode.Split(' ').Length < 5) { } else { yield return(new ValidationResult("Enter a 5 digit Zipcode")); } //throw new NotImplementedException(); }