
こんにちわ!ASP.NET MVC5でWeb勤務表作成しています。
https://teratail.com/questions/164940の続きになりますが、写真上の終業時刻が始業時刻より早まらないようにクライアントサイド検証をかけたいです。
こちらのサイトhttp://kobarin.hateblo.jp/?page=1499151648を参考にしてExpressiveAnnotationsのAssertThatを使用したのですが、何も検証がかかりませんでした(おそらくTimeSpan型がAssertThatで判定出来ないのではないのかと思います)。
何か良い方法がありましたら教えてください。
モデル:
public class SampleKintai { public int Id { get; set; } public string Emp_num { get; set; } public System.DateTime Date { get; set; } [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh\:mm}"), DataType(System.ComponentModel.DataAnnotations.DataType.Time)] [RegularExpression(@"((([0-1][0-9])|(2[0-3]))(:[0-5][0-9])(:[0-5][0-9])?)", ErrorMessage = "00:00~23:59で入力してください")] public Nullable<System.TimeSpan> Open { get; set; } [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh\:mm}"), DataType(System.ComponentModel.DataAnnotations.DataType.Time)] [RegularExpression(@"((([0-1][0-9])|(2[0-3]))(:[0-5][0-9])(:[0-5][0-9])?)", ErrorMessage = "00:00~23:59で入力してください")] [AssertThat("Open < Close", ErrorMessage = "終業時刻は始業時刻より遅くなければなりません")] public Nullable<System.TimeSpan> Close { get; set; } [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh\:mm}"), DataType(System.ComponentModel.DataAnnotations.DataType.Time)] [RegularExpression(@"((([0-1][0-9])|(2[0-3]))(:[0-5][0-9])(:[0-5][0-9])?)", ErrorMessage = "00:00~23:59で入力してください")] public Nullable<System.TimeSpan> Rest { get; set; } [DisplayFormat(DataFormatString = "{0:hh\:mm}")] public Nullable<System.TimeSpan> Worktime { get; set; } [DisplayFormat(DataFormatString = "{0:hh\:mm}")] public Nullable<System.TimeSpan> Overtime { get; set; } public int Situation { get; set; } [StringLength(20,ErrorMessage = "※入力は全角20文字以内")] public string Remark { get; set; } }





回答1件
あなたの回答
tips
プレビュー