Mvc_model實體資料驗證

來源:互聯網
上載者:User

標籤:ror   style   註冊   jquery   get   nbsp   false   uml   資料驗證   

MVC提供了很方便的資料驗證,只需要在model裡加入相關的正則等,那麼就會在前台裡產生相關的驗證指令碼。需要引用兩個js檔案:

jquery.validate.min.js

jquery.validate.unobtrusive.min.js

 

[Display(Name = "轉入金額")]        [Required(AllowEmptyStrings = false, ErrorMessage = "請輸入轉賬金額")]        [Range(100, 20000, ErrorMessage = "輸入的金額只能在100元到2萬元之間")]        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "轉入的金額必須為整數")]        public decimal Amount { get; set; }        /// <summary>        /// 交易密碼        /// </summary>        [Display(Name = "交易密碼")]        [StringLength(20, MinimumLength = 6, ErrorMessage = "{0}的長度在{2}至{1}個字元間")]        [Required(AllowEmptyStrings = false, ErrorMessage = "請輸入交易密碼")]        [DataType(DataType.Password)]        public string TradingPassword { get; set; }    [StringLength(10, MinimumLength = 4, ErrorMessage = "{0}的長度必須大於{2}個字元並小於{1}個字元")]    [Display(Name = "密碼")]    public virtual string LogPassword { get; set; }    [StringLength(10, ErrorMessage = "{0}的長度不能大於{1}個字元")]    [Display(Name = "姓名")]    public virtual string RealName { get; set; }    [Display(Name = "出生日期")]    //[Range(typeof(DateTime), "2011-12-31", "1950-1-1", ErrorMessage = "{0}的範圍是{1}到{2}")]    public virtual DateTime Birthday { get; set; }    [RegularExpression(@"\d{17}[\d|X]|\d{15}", ErrorMessage = "{0}的格式不正確")]    [Display(Name = "社會安全號碼碼")]    public virtual string IdentityNo { get; set; }    [RegularExpression(@"[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}", ErrorMessage = "{0}的格式不正確")]    [Display(Name = "郵箱")]    public virtual string Email { get; set; }        [Required(ErrorMessage = "註冊人郵箱不可為空")]        [RegularExpression(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "郵箱不正確")]        public string Email { get; set; }

 

Mvc_model實體資料驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.