Question: I am creating a simple asp.net core webapi which accepts a model from request. One of the property of the model is string but i want to accept only 10 digit numbers to this property. I am unable to change to int as it is used across all other places.

```
    [MaxLength(10, ErrorMessage = "Valid Learner Number must be supplied")]
    public string LearnerNumber{ get; set; }

```

Answer: 
You can use RegularExpression:

```
 [RegularExpression("^\\d{10}$", ErrorMessage = "Valid Learner Number must be supplied")]
 public string LearnerNumber{ get; set; }

```
Use this regular expression that matches exactly ten digits from beginning to end of an input string:

```
@"^(\d{10})$"

```