model下的驗證
[Required(ErrorMessage ="*")]
[Range(100, 50000, ErrorMessage = "金額範圍: 300 - 50000")]
[RegularExpression("[A-Za-z0-9]{3,8}", ErrorMessage = "限定為3-8個英文或數字")]
[RegularExpression(@"[\D]{2,6}$", ErrorMessage = "限定為2-6個中文字!")]
[RegularExpression("[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2}", ErrorMessage = "日期格式不正確")]
[Compare("loginPW", ErrorMessage = "兩次輸入密碼不一致")]
[Required(ErrorMessage = "*輸入密碼不一致"), Compare("loginPW")]
[StringLength(15, MinimumLength = 6, ErrorMessage = "長度限制為6-15個字元")]
//驗證時間 例: 8:30am
[RegularExpression(@"^([1-9]|1[0-2]):[0-5][0-9](am|pm)$", ErrorMessage = "輸入格式不正確")]
例2: 08:30 前面請多加一個0
[RegularExpression(@"^(0[1-9]|1[0-2]):[0-5][0-9](am|pm)$", ErrorMessage = "輸入格式不正確")]
//格式化日期
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
沒有留言:
張貼留言