2

以下のように検証を使用しています。

[Required(ErrorMessage = "Please provide 10 digit mobile number without spaces and without country code (+91)")]
[Integer(ErrorMessage = "Please provide 10 digit mobile number without spaces and without country code (+91)")]
[Range(1000000000, 9999999999, ErrorMessage = "10 digit mobile number only without spaces and without country code (+91)")]
[Display(Name = "Mobile Number")]
public int MobileNo { get; set; }

と言って検証に常に失敗していますThe value '9999999998' is invalid.。私は何か間違ったことをしていますか?

4

3 に答える 3

13

これを試して:

[RegularExpression("^[0-9]{10}$", ErrorMessage = "Invalid Mobile No")]
于 2012-05-25T12:02:19.997 に答える
7

Int32タイプが格納できる最大値は2,147,483,648です。あなたはあふれています。電話番号を表すために整数型を使用しているのはなぜですか?文字列はより適応しているようです。

于 2012-05-25T11:59:09.657 に答える
2

Integer(Int32)が保持できる最大値は2,147,483,647です。したがって、IntをLongまたはStringに置き換える方がよいでしょう。

于 2012-05-25T11:59:24.303 に答える