InputMask

The InputMask control allows you to validate and format user input as it is entered, preventing invalid data.

To use the InputMask control, set the mask property to a string that specifies the valid character classes for each input\ position, as described in the InputMask documentation.

Here are a few examples to demonstrate:




1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1InputController : Controller
    {
        // GET: InputMask
        public ActionResult InputMask()
        {
            return View();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<h1>
    @Html.Raw(Resources.C1Input.InputMask_Title)
</h1>
 
<p>
    @Html.Raw(Resources.C1Input.InputMask_Text1)
</p>
<p>
    @Html.Raw(Resources.C1Input.InputMask_Text2)
</p>
<p>
    @Html.Raw(Resources.C1Input.InputMask_Text3)
</p>
 
<div class="demo-settings">
    <label for="theSSN">@Html.Raw(Resources.C1Input.InputMask_Text4)</label>
    @Html.C1().InputMask().Id("theSSN").Mask("000-00-0000")
    <br>
    <label for="theZip">@Html.Raw(Resources.C1Input.InputMask_Text5)</label>
    @Html.C1().InputMask().Id("theZip").Mask("00000")
    <br>
    <label for="theZip4">@Html.Raw(Resources.C1Input.InputMask_Text6)</label>
    @Html.C1().InputMask().Id("theZip4").Mask("00000-0000")
    <br>
    <label for="thePhone">@Html.Raw(Resources.C1Input.InputMask_Text7)</label>
    @Html.C1().InputMask().Id("thePhone").Mask("(999) 000-0000")
</div>