Email model validation with DataAnnotations and DataType

前端 未结 4 1731
说谎
说谎 2020-12-01 06:08

I have following model:

public class FormularModel
{
    [Required]
    public string Position { get; set; }
    [Required]
    [DataType(DataType.EmailAddre         


        
4条回答
  •  情歌与酒
    2020-12-01 06:40

    I have looked at the source code (reverse engineered by Reflector) and DataType variants are actually not even implemented! (This was for DateType.Date)

    So it is not going to work.

    I would personally use RegexValidation for email.


    For clarity, here is the implementation of IsValid in class DataTypeAttribute:

    public override bool IsValid(object value)
    {
        return true;
    }
    

提交回复
热议问题