public static void CheckEmailFormat(string email) { bool isValid = ValidEmailRegex.IsMatch(email); if (!isValid) { throw new WrongEmailFormatException("El formato del email no es válido"); } }
//Email Address Validation private bool IsEmailValid(TextBox box, bool ok, int tabIndex) { if (!ValidEmailRegex.IsMatch(box.Text)) { ok = false; box.Focus(); tabControl1.SelectedIndex = tabIndex; errorProvider1.SetError(box, "Please provide valid email Address([email protected])"); } return(ok); }
public static void Username(string username, string parameterName, string field = null) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentException($"Username can't be an empty or whitespace string", parameterName + (field == null ? string.Empty : "." + field)); } if (username.Length < MinUsernameLenght) { throw new ArgumentException($"Username must be at least {MinUsernameLenght} characters", parameterName + (field == null ? string.Empty : "." + field)); } if (!ValidUsernameRegex.IsMatch(username) && !ValidEmailRegex.IsMatch(username)) { throw new ArgumentException("Username contains invalid characters", parameterName + (field == null ? string.Empty : "." + field)); } }
public static bool IsValidEmailAddress(this string address) => ValidEmailRegex.IsMatch(address);