Example of Default Functionalities in ASP.NET MVC MaskedTextBox Control
This sample demonstrates that the default functionalities of MaskedTextBox component. Enter numeric value for “Mobile Number” textbox then press tab key and then enter “Country ISO Code” in alphabetic format, then type “D.O.B” in numeric format. Finally enter the “Product Key” in alpha numeric format.
Mobile Number
Country ISO Code
D.O.B
Product Key
@Html.UiMaskedTextBox("mask1", new UiMaskedTextBoxOptions { Mask = "000-000-0000" })
@Html.UiMaskedTextBox("mask2", new UiMaskedTextBoxOptions { Mask = ">LL / LLL" })
@Html.UiMaskedTextBox("mask3", new UiMaskedTextBoxOptions { Mask = "00/00/0000" })
@Html.UiMaskedTextBox("mask4", new UiMaskedTextBoxOptions { Mask = ">AAAAA-AAAAA-AAAAA-AAAAA" })
<style>
.content-wrapper { width: 90%; max-width: 400px; margin: 0 auto; min-width: 185px; }
.content-wrapper .control-label { padding: 24px 0 4px; font-size: 12px; opacity: 0.7; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 150px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
</style>
<div class="control-section">
<div class="content-wrapper">
<div class="control-label">Mobile Number</div>
@Html.UiMaskedTextBox("mask1", new UiMaskedTextBoxOptions { Mask = "000-000-0000" })
<div class="control-label">Country ISO Code</div>
@Html.UiMaskedTextBox("mask2", new UiMaskedTextBoxOptions { Mask = ">LL / LLL" })
<div class="control-label">D.O.B</div>
@Html.UiMaskedTextBox("mask3", new UiMaskedTextBoxOptions { Mask = "00/00/0000" })
<div class="control-label">Product Key</div>
@Html.UiMaskedTextBox("mask4", new UiMaskedTextBoxOptions { Mask = ">AAAAA-AAAAA-AAAAA-AAAAA" })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MaskedTextBoxController : Controller
{
// The page is Views/MaskedTextBox/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The MaskedTextBox is a textbox extended component that allows the user to enter only the valid input based on the provided mask. It is used to get the input with specific formats like Phone number, Date, Time, IP, Social security number, etc.
MaskedTextBox supports the list of mask elements based on the standard MSDN mask elements.