Is the DataTypeAttribute validation working in MVC2?

后端 未结 5 1452
鱼传尺愫
鱼传尺愫 2020-12-03 07:26

As far as I know the System.ComponentModel.DataAnnotations.DataTypeAttribute not works in model validation in MVC v1. For example,

public class Model
{
  [Da         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 07:53

    Alternatively, you can directly use RegularExpression attribute on your field instead of creating your own attribute that is in the end going to check for a regex matching.

    [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = PaErrorMessages.InvalidEmailAddress)]
    public string Email { get; set; }
    

提交回复
热议问题