1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- namespace InvestTracker.Validation
- {
- public class Email : ValidationRule
- {
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- string? email = value.ToString();
- if (email == null)
- {
- return new ValidationResult(
- false,
- "Адрес электронной почты не задан"
- );
- }
- // В почте должен быть знак @ и точка после такого знака
- int dogIndex = email.IndexOf("@");
- if (dogIndex == -1)
- {
- return new ValidationResult(
- false,
- "Адрес почты обязан содержать символ \"@\""
- );
- }
- int dotIndex = email.IndexOf('.', dogIndex);
- if (dotIndex == -1)
- {
- return new ValidationResult(
- false,
- "После символа \"@\" должен следовать символ \".\""
- );
- }
- return ValidationResult.ValidResult;
- }
- }
- }
|