开发者

Force formatting text encoded by user

开发者 https://www.devze.com 2023-02-22 17:49 出处:网络
I used a ViewModel class as described below: public class ProductCreateModel { [Display开发者_运维问答Name(\"Id product:\")]

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}?$")
0

精彩评论

暂无评论...
验证码 换一张
取 消