2014-02-28 199 views
0

我有門牌號碼和其數據類型的TextBoxstring但我必須把驗證這個TextBox,使其只接受integer value.I必須使用DataAnnotations和自定義驗證這一點。驗證通過自定義的驗證

+0

使用JavaScript的正則表達式,並通過jQuery的驗證。您也可以使用萬無一失的http://foolproof.codeplex.com/ – Nilesh

+0

謝謝..但我只能使用數據註釋和自定義驗證。 – user3206357

+0

是的,您可以在數據註釋中使用正則表達式來驗證字符串。檢查此堆棧鏈接http://stackoverflow.com/questions/8431007/how-can-i-set-a-regularexpression-data-annotations-regular-expression-argument – Nilesh

回答

0

我會用正則表達式或範圍數據註釋

[RegularExpression(@"^\d{1,}$", ErrorMessage = "HouseNumber error")]

[Range(0, int.MaxValue, ErrorMessage = "HouseNumber error")] public string HouseNumber{ get; set; }