I used a ViewModel class as described below:
public class ProductCreateModel
{
[Display开发者_运维问答Name("Id product:")]
[Required(ErrorMessage = "Please enter the id.")]
public string IdProduct { get; set; }
[DisplayName("Description:")]
[Required(ErrorMessage = "Please enter the description.")]
public string Description { get; set; }
}
How can I proceed to force users to encode an id product in format 11.111 so 2 numbers followed by dot followed by 3 numbers.
Thank you for your time.
You could use a Regex validator:
[DisplayName("Id product:")]
[Required(ErrorMessage = "Please enter the id.")]
[RegularExpression(@"^[0-9]{2}\.[0-9]{3}$")]
public string IdProduct { get; set; }
You can use a regular expression validation attribute like this:
[RegularExpression(@"^\d{2}\.\d{3}?$")
精彩评论