ASP.NETMVC验证:字符串以000开头,后跟另外6个数字
创始人
2024-09-19 08:00:13
0
  1. 创建一个自定义验证类,用于验证指定的字符串是否符合要求。
public class MyValidationAttribute: ValidationAttribute
{
    public override bool IsValid(object value)
    {
        if (value == null)
        {
            return true;
        }

        string strValue = value.ToString();

        // 检查字符串是否以000开头,并且之后跟着6个数字
        Regex regex = new Regex(@"^000\d{6}$");
        return regex.IsMatch(strValue);
    }
}
  1. 在模型类的相应属性上使用自定义验证类。
public class MyModel
{
    [MyValidation(ErrorMessage = "必须以000开头,后跟6个数字")]
    public string MyProperty{ get; set; }
}

这样,当你在创建一个MyModel对象时,如果MyProperty的值不符合要求,那么自定义验证类会返回错误消息。

相关内容

热门资讯

透视透视!aapoker透视方... 透视透视!aapoker透视方法(透视)万能辅助器(好像存在有挂)1、aapoker透视方法系统规律...
透视规律!德扑圈透视(透视)透... 透视规律!德扑圈透视(透视)透视辅助软件激活码(果然有挂)1、完成德扑圈透视透视辅助安装,帮助玩家取...
透视ai!德扑圈透视(透视)辅... 透视ai!德扑圈透视(透视)辅助软件(真是存在有挂)德扑圈透视辅助器中分为三种模型:德扑圈透视软件透...
透视安卓版!aapoker怎么... 透视安卓版!aapoker怎么设置提高好牌几率(透视)ai插件(原来真的是有挂)1、aapoker怎...
透视代打!aapoker辅助怎... 透视代打!aapoker辅助怎么用(透视)透视脚本(总是真的有挂)1、aapoker辅助怎么用透视辅...
透视插件!德普之星透视辅助软件... 透视插件!德普之星透视辅助软件激活码(透视)透视辅助软件下载(一直真的有挂)小薇(透视辅助)致您一封...
透视ai代打!aapoker透... 透视ai代打!aapoker透视脚本入口(透视)万能辅助器(一贯是真的有挂);1、实时aapoker...
透视教程!德扑圈透视挂(透视)... 透视教程!德扑圈透视挂(透视)辅助软件(确实真的是有挂)1、德扑圈透视挂系统规律教程、德扑圈透视挂辅...
透视脚本!aapoker怎么选... 透视脚本!aapoker怎么选牌(透视)透视方法(好像是有挂)1、打开软件启动之后找到中间准星的标志...
透视代打!aapoker免费透... 透视代打!aapoker免费透视脚本(透视)透视脚本入口(真是真的是有挂)1、aapoker免费透视...