验证在MVC3文本 [英] Validation for textbox in MVC3

查看:120
本文介绍了验证在MVC3文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助。我与MVC3剃刀应用程序的工作。我需要在这样的方式中,起始2个字符必须是PR和第4个字符必须是2,以验证对视图(.cshtml文件)的文本框。这就是要求。我将如何实现这个功能?任何建议,这将是很大的帮助。感谢您的precious时间。

I need your help. I am working with MVC3-Razor application. I need to validate a textbox on View (.cshtml file) in such a way that, the starting 2 characters must be "PR" and 4th character must be "2". This is the requirement. How would i achieve this functionality? Any suggestions, it would be great help. Thanks for your precious time.

推荐答案

型号

public class RegisterModel
{
      public int ID { get; set; }

      [RegularExpression(@"^PR[a-zA-Z0-9]2([a-zA-Z0-9]*)$", ErrorMessage = "Please enter valid Name.")]
      [Required(ErrorMessage = "Name is required.")]
      public string Name { get; set; }
}

查看

@using (Html.BeginForm("DYmanicControllerPage", "Test", FormMethod.Post, new { id = "FrmIndex" }))
{ 
      <div>
          @Html.LabelFor(m => m.Name)
          @Html.TextBoxFor(m => m.Name)
          @Html.ValidationMessageFor(m => m.Name)
      </div>
}

这篇关于验证在MVC3文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆