2013-06-25 30 views
10

RegularExpression(@"^\d{1,15}$")] kullanarak, kullanıcı en fazla hata mesajı döndürür uzunluğunda 15, için tuşlara istediğiniz bu doğru değilse 'bir iletişim numarası için 15 haneye kadar girin'Düzenli ifade hata mesajı

kullanıcı Ben hata mesajı ile kaldım bu başaramazsa
[Required(ErrorMessage = ("Please enter up to 15 digits for a contact number")), Display(Name = "Contact Number"), RegularExpression(@"^\d{1,15}$")] 
public string ContactNumber { get; set; } 

:

The field Contact Number must match the regular expression '^\d{1,15}$'. 

yerine 'Please enter up to 15 digits for a contact number' arasında ... herkes neden biliyor? teşekkürler

cevap

30

Sen (kesinlikle nedeniyle düzenli ifadenin bu durumda gerek yoktur) RequiredAttribute için ErrorMessage atadınız. Yani:

[Display(Name = "Contact Number")] 
[RegularExpression(@"^\d{1,15}$", ErrorMessage = "Please enter up to 15 digits for a contact number")] 
public string ContactNumber { get; set; } 
+0

Yardımcılar için teşekkürler – John

4

Sen RegularExpression özniteliği değil Required özelliğinde mesajınızı yerleştirmek gerekir.

Hata iletinizi Required özniteliğine eklediniz, yani bu, alan boş olduğunda görüntülenecek demektir.