【问题标题】:Want to add a validation using regular expression the format should be like this xxxxx-xxxxxxx-x想要使用正则表达式添加验证,格式应该是这样的 xxxxx-xxxxxxx-x
【发布时间】:2014-08-17 22:48:19
【问题描述】:

我正在尝试使用正则表达式进行验证,以从文本框 xxxxx-xxxxxxx-x 获取类似的值 这是我正在尝试的方法

 [Required]
    [Display(Name = "CNIC")]
    [RegularExpression(@"^\(([0-9]{5})[-]([0-9]{7})[-][0-9]{1}\)$", ErrorMessage = "Entered CNIC format is not valid.")]
    public string Cnic { get; set; }

但它显示 cnic 格式无效

【问题讨论】:

    标签: c# regex asp.net-mvc


    【解决方案1】:
    [RegularExpression(@"^[0-9+]{5}-[0-9+]{7}-[0-9]{1}$", ErrorMessage = "Entered CNIC format is not valid.")]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 2016-07-31
      相关资源
      最近更新 更多