public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if (string.IsNullOrWhiteSpace(Name)) yield return new ValidationResult("Name is required."); if (string.IsNullOrWhiteSpace(SSN)) yield return new ValidationResult("SSN is required."); if (string.IsNullOrWhiteSpace(Gender)) yield return new ValidationResult("Gender is required."); if (Address == null) yield return new ValidationResult("Address is required."); if (!Birthdate.HasValue) yield return new ValidationResult("Birthdate is required."); if (string.IsNullOrWhiteSpace(Email)) yield return new ValidationResult("Email is required."); var emailValidator = new EmailAddressAttribute(); if (!emailValidator.IsValid(Email)) yield return new ValidationResult("Invalid email."); if (string.IsNullOrWhiteSpace(Password)) yield return new ValidationResult("Password is required."); }
private bool IsValidEmail(string emailAddress) { if(string.IsNullOrWhiteSpace(emailAddress)) { return false; } bool valid = false; var emails = emailAddress.Split(',').Select(x => x.Trim()).ToArray(); if(emails.Any()) { foreach(string email in emails) { valid = new EmailAddressAttribute().IsValid(email); } } else { valid = new EmailAddressAttribute().IsValid(emailAddress); } if(valid) { //Do not send email to dispoable email address valid = !DisposableEmailValidator.IsDisposableEmail(this.Database, emailAddress); } return valid; }
public static void Validate_throws_for_invalid_local_part() { var attribute = new EmailAddressAttribute(); Assert.Throws<ValidationException>(() => attribute.Validate("@someDomain.com", s_testValidationContext)); // no local part Assert.Throws<ValidationException>(() => attribute.Validate("@[email protected]", s_testValidationContext)); // multiple @'s }
public EmailAddressAdapterTests() { attribute = new EmailAddressAttribute(); metadata = new DataAnnotationsModelMetadataProvider() .GetMetadataForProperty(null, typeof(AdaptersModel), "EmailAddress"); adapter = new EmailAddressAdapter(metadata, new ControllerContext(), attribute); }
public static void Validate_throws_InvalidOperationException_if_ErrorMessage_and_ErrorMessageResourceName_are_set() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = "SomeErrorMessage"; attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName"; Assert.Throws<InvalidOperationException>(() => attribute.Validate("InvalidEmailAddress", s_testValidationContext)); }
public static void Validate_throws_for_invalid_domain_name() { var attribute = new EmailAddressAttribute(); Assert.Throws<ValidationException>(() => attribute.Validate("someName", s_testValidationContext)); // no domain Assert.Throws<ValidationException>(() => attribute.Validate("someName@", s_testValidationContext)); // no domain Assert.Throws<ValidationException>(() => attribute.Validate("someName@[email protected]", s_testValidationContext)); // multiple @'s }
public static void GetValidationResult_ErrorMessageSet_ReturnsOverridenValue() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = "SomeErrorMessage"; var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = nameof(EmailClassToBeTested.EmailPropertyToBeTested); var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage); }
public void IsValid () { var sla = new EmailAddressAttribute (); for (int i = 0; i < ValidAddresses.Length; i++) Assert.IsTrue (sla.IsValid (ValidAddresses[i]), "#A1-{0}", i); for (int i = 0; i < InvalidAddresses.Length; i++) Assert.IsFalse (sla.IsValid (InvalidAddresses[i]), "#B1-{0}", i); }
public static void Validate_successful_for_valid_domain_part() { var attribute = new EmailAddressAttribute(); AssertEx.DoesNotThrow(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // Simple valid value AssertEx.DoesNotThrow(() => attribute.Validate("someName@some~domain.com", s_testValidationContext)); // With tilde AssertEx.DoesNotThrow(() => attribute.Validate("someName@some_domain.com", s_testValidationContext)); // With underscore AssertEx.DoesNotThrow(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // numbers are valid AssertEx.DoesNotThrow(() => attribute.Validate("someName@someDomain\uFFEF.com", s_testValidationContext)); // With valid \u character }
public static void Validate_successful_for_valid_local_part() { var attribute = new EmailAddressAttribute(); AssertEx.DoesNotThrow(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // Simple valid value AssertEx.DoesNotThrow(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // numbers are valid AssertEx.DoesNotThrow(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // With dot in name AssertEx.DoesNotThrow(() => attribute.Validate("\[email protected]", s_testValidationContext)); // With valid \u character AssertEx.DoesNotThrow(() => attribute.Validate("!#$%&'*+-/=?^_`|[email protected]", s_testValidationContext)); // With valid (but unusual) characters AssertEx.DoesNotThrow(() => attribute.Validate("\"firstName.lastName\"@someDomain.com", s_testValidationContext)); // quotes around whole local part }
public string Subscribe(string email) { string returnValue = "false"; EmailAddressAttribute emailValidator = new EmailAddressAttribute(); if (!string.IsNullOrEmpty(email) && !email.Equals("*****@*****.**") && emailValidator.IsValid(email)) { SubscriberMng.Instance.CreateAndAddSubscriber(email, this); returnValue = "true"; } return returnValue; }
public static void Validate_throws_for_invalid_domain_name() { var attribute = new EmailAddressAttribute(); Assert.Throws<ValidationException>(() => attribute.Validate("someName", s_testValidationContext)); // no domain Assert.Throws<ValidationException>(() => attribute.Validate("someName@", s_testValidationContext)); // no domain Assert.Throws<ValidationException>(() => attribute.Validate("someName@someDomain", s_testValidationContext)); // Domain must have at least 1 dot Assert.Throws<ValidationException>(() => attribute.Validate("someName@[email protected]", s_testValidationContext)); // multiple @'s Assert.Throws<ValidationException>(() => attribute.Validate("someName@\0.com", s_testValidationContext)); // illegal character Assert.Throws<ValidationException>(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // two adjacent dots not allowed }
public void IsValid () { var sla = new EmailAddressAttribute (); Assert.IsTrue (sla.IsValid (null), "#A1-1"); Assert.IsFalse (sla.IsValid (String.Empty), "#A1-2"); Assert.IsFalse (sla.IsValid ("string"), "#A1-3"); Assert.IsTrue (sla.IsValid ("*****@*****.**"), "#A1-4"); Assert.IsTrue (sla.IsValid ("*****@*****.**"), "#A1-5"); Assert.IsFalse (sla.IsValid (123), "#A1-6"); Assert.IsFalse (sla.IsValid (DateTime.Now), "#A1-7"); }
public override IEnumerable<ValidationResult> Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) { var asString = value.ToString(); var emailVal = new EmailAddressAttribute(); if (emailVal.IsValid(asString) == false) { //TODO: localize these! yield return new ValidationResult("Email is invalid", new[] { "value" }); } }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if (string.IsNullOrWhiteSpace(Email)) yield return new ValidationResult("Email is required."); var emailValidator = new EmailAddressAttribute(); if (!emailValidator.IsValid(Email)) yield return new ValidationResult("Invalid email."); if (string.IsNullOrWhiteSpace(Password)) yield return new ValidationResult("Password is required."); }
public static void Validate_throws_for_invalid_local_part() { var attribute = new EmailAddressAttribute(); Assert.Throws<ValidationException>(() => attribute.Validate("@someDomain.com", s_testValidationContext)); // no local part Assert.Throws<ValidationException>(() => attribute.Validate("\[email protected]", s_testValidationContext)); // illegal character Assert.Throws<ValidationException>(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // initial dot not allowed Assert.Throws<ValidationException>(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // final dot not allowed Assert.Throws<ValidationException>(() => attribute.Validate("*****@*****.**", s_testValidationContext)); // two adjacent dots not allowed Assert.Throws<ValidationException>(() => attribute.Validate("firstName(comment)[email protected]", s_testValidationContext)); // parens not allowed Assert.Throws<ValidationException>(() => attribute.Validate("firstName\"middleName\"*****@*****.**", s_testValidationContext)); // quotes in middle not allowed }
public ActionResult contactMail() { string Name = Request.Form["Name"]; string Message = Request.Form["Message"]; string Email = Request.Form["Email"]; EmailAddressAttribute emailCheck = new EmailAddressAttribute(); if (emailCheck.IsValid(Email)) { SendMailInner("Admin", "Contactmail van " + Name, "Dit schreef " + Name + ":\n" + Message + "\n" + "Mail terug op: " + Email); } return Redirect("/"); }
public static bool validateEmail(string uemail) { bool check = true; var emailcheck = new EmailAddressAttribute(); if (emailcheck.IsValid(uemail)) { check = true; } else { check = false; } return check; }
public virtual void CreateAccount(string username, string password, string email) { if (SecuritySettings.Instance.EmailIsUsername) { username = email; } if (String.IsNullOrWhiteSpace(username)) throw new ArgumentException("username"); if (String.IsNullOrWhiteSpace(password)) throw new ArgumentException("password"); if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("email"); ValidatePassword(password); EmailAddressAttribute validator = new EmailAddressAttribute(); if (!validator.IsValid(email)) { throw new ValidationException("Email is invalid."); } if ((!SecuritySettings.Instance.EmailIsUsername && UsernameExists(username)) || EmailExists(email)) { throw new ValidationException("Username/Email already in use."); } using (var tx = new TransactionScope()) { var account = UserAccount.Create(username, password, email); this.userRepository.Add(account); if (this.notificationService != null) { if (SecuritySettings.Instance.RequireAccountVerification) { this.notificationService.SendAccountCreate(account); } else { this.notificationService.SendAccountVerified(account); } } this.userRepository.SaveChanges(); tx.Complete(); } }
/// <summary> /// Determines whether this instance equals a specified route. /// </summary> /// <param name="request">The request.</param> /// <param name="route">The route to compare.</param> /// <param name="parameterName">The name of the parameter.</param> /// <param name="values">A list of parameter values.</param> /// <param name="routeDirection">The route direction.</param> /// <returns> /// <c>True</c> if this instance equals a specified route; otherwise, <c>false</c>. /// </returns> public bool Match( HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection) { object value; if (values.TryGetValue(parameterName, out value) && value != null) { var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); var emailAttribute = new EmailAddressAttribute(); return emailAttribute.IsValid(valueString); } return false; }
public void TestGetEmailAddress() { EmailAddressAttribute emailAddressAttribute = new EmailAddressAttribute(); string emailAddress = RandomValueGenerator.GetEmailAddress(); Assert.IsTrue(emailAddressAttribute.IsValid(emailAddress)); }
public static void Validate_successful_for_null_address() { var attribute = new EmailAddressAttribute(); AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // Null is valid }
public static void GetValidationResult_returns_ErrorMessage_from_resource_if_ErrorMessageResourceName_and_ErrorMessageResourceType_both_set() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty"; attribute.ErrorMessageResourceType = typeof(ErrorMessageResources); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal( "Error Message from ErrorMessageResources.InternalErrorMessageTestProperty", validationResult.ErrorMessage); }
public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set() { var attribute = new EmailAddressAttribute(); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext)); }
public static void EmailAddressAttribute_creation_DataType_and_CustomDataType() { var attribute = new EmailAddressAttribute(); Assert.Equal(DataType.EmailAddress, attribute.DataType); Assert.Null(attribute.CustomDataType); }
public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = "SomeErrorMessage"; var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage); }
public static void Validate_throws_InvalidOperationException_if_ErrorMessageResourceType_set_but_ErrorMessageResourceName_not_set() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessageResourceName = null; attribute.ErrorMessageResourceType = typeof(ErrorMessageResources); Assert.Throws<InvalidOperationException>(() => attribute.Validate("InvalidEmailAddress", s_testValidationContext)); }
public static void Validate_throws_InvalidOperationException_if_ErrorMessage_is_null() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = null; // note: this overrides the default value Assert.Throws<InvalidOperationException>(() => attribute.Validate("InvalidEmailAddress", s_testValidationContext)); }
public static bool IsValidEmail(string email) { var emailAttribute = new EmailAddressAttribute(); return emailAttribute.IsValid(email); }
public void ValidateEmailAddress(string emailAddress) { if (emailAddress == null) { throw new EmailAddressException(UserConstants.UserEmailAddressInvalid); } var mailAddress = new EmailAddressAttribute(); if (!mailAddress.IsValid(emailAddress)) { throw new EmailAddressException(UserConstants.UserEmailAddressInvalid); } }