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的值不符合要求,那么自定义验证类会返回错误消息。

相关内容

热门资讯

透视代打!wepoker代打辅... 透视代打!wepoker代打辅助,wepoker有什么规律(详细插件下载)1、让任何用户在无需wep...
透视工具!aapoker ai... 透视工具!aapoker ai插件(透视)aa poker透视软件,必胜教程(有挂解密)该软件可以轻...
透视真的!wepoker透视破... 透视真的!wepoker透视破解版,wepoker到底有没有透视(详细开辅助能查到);1)wepok...
透视讲解!aapoker ai... 透视讲解!aapoker ai插件(透视)aapoker怎么设置提高好牌几率,wpk教程(有挂方法)...
透视好友!wepokerplu... 透视好友!wepokerplus外挂,wepoker辅助器是真的吗(详细辅助插件功能)1、该软件可以...
透视透视!aapoker怎么控... 透视透视!aapoker怎么控制牌(透视)aapoker辅助插件工具,爆料教程(有挂详情);1、完成...
透视好牌!wepoker提高好... 透视好牌!wepoker提高好牌率,wepoker是不是有人用挂(详细破解辅助插件);1、wepok...
透视了解!aa poker透视... 透视了解!aa poker透视软件(透视)aapoker免费透视脚本,总结教程(有挂解密)aapok...
透视挂透视!wepoker怎么... 透视挂透视!wepoker怎么挂底牌,wepoker轻量版透视系统(详细辅助器有哪些功能)1、起透看...
透视软件!aa poker透视... 透视软件!aa poker透视软件(透视)aapoker辅助怎么用,规律教程(有挂教程)1、超多福利...