0
我有門牌號碼和其數據類型的TextBox
是string
但我必須把驗證這個TextBox
,使其只接受integer
value.I必須使用DataAnnotations
和自定義驗證這一點。驗證通過自定義的驗證
我有門牌號碼和其數據類型的TextBox
是string
但我必須把驗證這個TextBox
,使其只接受integer
value.I必須使用DataAnnotations
和自定義驗證這一點。驗證通過自定義的驗證
我會用正則表達式或範圍數據註釋
[RegularExpression(@"^\d{1,}$", ErrorMessage = "HouseNumber error")]
或
[Range(0, int.MaxValue, ErrorMessage = "HouseNumber error")] public string HouseNumber{ get; set; }
使用JavaScript的正則表達式,並通過jQuery的驗證。您也可以使用萬無一失的http://foolproof.codeplex.com/ – Nilesh
謝謝..但我只能使用數據註釋和自定義驗證。 – user3206357
是的,您可以在數據註釋中使用正則表達式來驗證字符串。檢查此堆棧鏈接http://stackoverflow.com/questions/8431007/how-can-i-set-a-regularexpression-data-annotations-regular-expression-argument – Nilesh