---
title: "phone validation in Mvc"  
description: "phone validation in Mvc"  
author: "Anonymous User"  
published: 2018-05-31  
updated: 2018-06-08  
canonical: https://www.mindstick.com/forum/34500/phone-validation-in-mvc  
category: ".net"  
tags: ["asp.net mvc", "regex"]  
reading_time: 2 minutes  

---

# phone validation in Mvc

I want to [validate](https://www.mindstick.com/forum/1490/what-is-better-solution-for-validate-form-textboxs-value) [phone](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) no. using [data annotation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework)

```
 <li class="cell last" style="width: 60%;">
            @Html.TextBoxFor(model => model.PhoneNumber, new { @class = "textbox" }) @Html.ValidationMessageFor(model => model.PhoneNumber)
        </li>
```

## Replies

### Reply by Prakash nidhi Verma

hi folks, if you want to validation phone number annotation in MVC.

use this code which is shown below:

```
        <li class="cell last" style="width: 60%;">Phone Number:</li>         <li class="cell last" style="width: 60%;">
            @Html.TextBoxFor(model => model.PhoneNumber, new { @class = "textbox" }) @Html.ValidationMessageFor(model => model.PhoneNumber)
        </li>
```

please check your Models and Views properly:

```
@Html.LabelFor(model => model.PhoneNumber)
@Html.EditorFor(model => model.PhoneNumber)
@Html.ValidationMessageFor(model => model.PhoneNumber)
```

this [Data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) Annotation alone is enough if you need regex for validation. as you want to using data annotation so its helpful for you which is shown below:

Syntax:

```
[RegularExpression(@"^([0]|\+91[\-\s]?)?[789]\d{9}$", ErrorMessage = "Your entered Mobile No is not valid.")]
```

Code:

```
public class PersonModel
{
    [Display(Name = "Mobile Number:")]
    [Required(ErrorMessage = "Mobile Number is required.")]
    [RegularExpression(@"^([0-9]{10})$", ErrorMessage = "Your entered no is Invalid.")]
    public string MobileNumber { get; set; }
}
```

I hope, It will be helpful for you.

Happy Coding :)


---

Original Source: https://www.mindstick.com/forum/34500/phone-validation-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
