src/Framework/Validation/Validation.FluentValidation/Validators/PhoneValidator.cs

(完整代码) 733B

using System.Text.RegularExpressions;
using FluentValidation.Validators;

namespace NetModular.Lib.Validation.FluentValidation.Validators
{
    /// <summary>
    /// 手机号简单验证
    /// </summary>
    public class PhoneValidator : PropertyValidator
    {
        private const string Pattern = @"^1[345789]\d{9}$";
        private static Regex _regex;

        public PhoneValidator() : base("手机号无效")
        {
            _regex=new Regex(Pattern);
        }

        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context.PropertyValue == null)
                return false;

            return _regex.IsMatch(context.PropertyValue.ToString());
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。