// public Ad[] Ads {get; set; } public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { Regex reg = new Regex(@"\W"); sovadb001Entities0 db = new sovadb001Entities0(); //Не нулевой Email if (string.IsNullOrWhiteSpace(email)) { yield return(new ValidationResult("Введите email", new string[] { "email" })); } else { //корректный Email var regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.Compiled); var match = regex.Match(email); //if (reg.IsMatch(email)) //{ // yield return new ValidationResult("Символы запрещены", new string[] { "email" }); //} if (!(match.Success && match.Length == email.Length)) { yield return(new ValidationResult("Введите корректный email", new string[] { "email" })); } } if (string.IsNullOrWhiteSpace(password)) { yield return(new ValidationResult("Введите пароль", new string[] { "password" })); } else { if (password.Length < 5 || password.Length > 15) { yield return(new ValidationResult("Пароль должен быть больше 5 и меньше 15 символов", new string[] { "password" })); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { Regex reg = new Regex(@"\W"); sovadb001Entities0 db = new sovadb001Entities0(); //Не нулевой Email if (string.IsNullOrWhiteSpace(email)) { yield return(new ValidationResult("Введите email", new string[] { "email" })); } else { //корректный Email var regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.Compiled); var match = regex.Match(email); //if (reg.IsMatch(email)) //{ // yield return new ValidationResult("Символы запрещены", new string[] { "email" }); //} if (!(match.Success && match.Length == email.Length)) { yield return(new ValidationResult("Введите корректный email", new string[] { "email" })); } var anyUser = db.users.Any(p => string.Compare(p.email, email) == 0); if (anyUser) { yield return(new ValidationResult("Такой email уже зарегистрирован", new string[] { "email" })); } } //пароль не нулевой if (string.IsNullOrWhiteSpace(password)) { yield return(new ValidationResult("Введите пароль", new string[] { "password" })); } else { if (password.Length < 5 || password.Length > 15) { yield return(new ValidationResult("Пароль должен быть больше 5 и меньше 15 символов", new string[] { "password" })); } //пароли совпадают if (password != ConfirmPassword) { yield return(new ValidationResult("Пароли не совпадают", new string[] { "ConfirmPassword" })); } } if (string.IsNullOrWhiteSpace(name)) { yield return(new ValidationResult("Введите Имя", new string[] { "name" })); } else { if (name.Length <= 3 || name.Length > 15) { yield return(new ValidationResult("Имя быть больше 3 и меньше 15 символов", new string[] { "name" })); } if (reg.IsMatch(name)) { yield return(new ValidationResult("Символы запрещены", new string[] { "name" })); } } }