Data Annotation to validate confirm password

前端 未结 3 1395
醉梦人生
醉梦人生 2021-02-01 12:37

My User model has these data annotations to validate input fields:

[Required(ErrorMessage = \"Username is required\")]
[StringLength(16, ErrorMessage = \"Must be         


        
3条回答
  •  长发绾君心
    2021-02-01 13:02

    You can use the compare annotation to compare two values, and if you need to make sure it isn't persisted anywhere downstream (For example if you are using EF) You can also add NotMapped to ignore any entity->DB mapping

    For a full list of data annotations available, see here:

    https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations(v=vs.110).aspx

    [Required]
    [DataType(DataType.Password)]
    public string Password { get; set; }
    
    [Required]
    [DataType(DataType.Password)]
    [Compare("Password")]
    [NotMapped]
    public string ConfirmPassword { get; set; }
    

提交回复
热议问题