public bool Validate(int legislationType) { if (string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName)) { return(false); } if (string.IsNullOrWhiteSpace(Phone) && string.IsNullOrWhiteSpace(Email)) { return(false); } if (!PhoneNumberUtility.Validate(Phone) || !PhoneNumberUtility.Validate(Fax)) { return(false); } if (Address == null || !Address.ValidateForComplainant(legislationType)) { return(false); } return(true); }
public static bool IsValidPhoneNumber(this string value, int minLength = default, int maxLength = default) { value = value.Replace("+", string.Empty).TrimEnd(); value = PhoneNumberUtility.RemoveExtension(value); if (minLength != default) { if (value.Length < minLength) { return(false); } } if (maxLength != default) { if (value.Length > maxLength) { return(false); } } bool digitFound = false; foreach (char c in value) { if (char.IsDigit(c)) { digitFound = true; break; } } if (!digitFound) { return(false); } foreach (char c in value) { if (!(char.IsDigit(c) || char.IsWhiteSpace(c) || PhoneNumberUtility.AdditionalPhoneNumberCharacters.IndexOf(c) != -1)) { return(false); } } return(true); }
public void Sanitize() { Phone = PhoneNumberUtility.Sanitize(Phone); Fax = PhoneNumberUtility.Sanitize(Fax); Address?.Sanitize(); }