亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼

 更新時(shí)間:2022年09月11日 12:48:16   作者:Darren Ji  
這篇文章介紹了ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在ASP.NET MVC中,可以使用RegularExpression特性來(lái)驗(yàn)證手機(jī)號(hào)碼。

    public class Customer
    {
        [Required(ErrorMessage = "必填")]
        [Display(Name = "手機(jī)號(hào)")]
        [RegularExpression(@"^1[3458][0-9]{9}$", ErrorMessage = "手機(jī)號(hào)格式不正確")]
        public string PhoneNumber { get; set; }
    }

在HomeController中:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new Customer());
        }
        [HttpPost]
        public ActionResult Index(Customer customer)
        {
            if (ModelState.IsValid)
            {
                return Content("ok");
            }
            else
            {
                return View(customer);
            }
        }
    }

在Views/Shared/_Layout.cshtml中,必須引用異步驗(yàn)證的相關(guān)js。

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")

在Home/Index.cshtml中:

@model MvcApplication1.Models.Customer
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
    @Html.LabelFor(m => m.PhoneNumber)
    @Html.TextBoxFor(m => m.PhoneNumber)
    @Html.ValidationMessageFor(m => m.PhoneNumber)
    <br/>
    <input type="submit" value="提交"/>
}

到此這篇關(guān)于ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論