我在我的 MVC 项目中为电子邮件 ID 和确认电子邮件 ID 使用了 2 个文本框。
在视图中:
@Html.TextBoxFor(m => m.Email, new { maxlength = 50, title = "Enter Email" })
@Html.ValidationMessageFor(m => m.Email)
@Html.TextBoxFor(m => m.ReEmail, new { maxlength = 50, title = "Confirm Email" })
@Html.ValidationMessageFor(m => m.ReEmail)
在视图模型上:
[DisplayName("Email")]
[Required(ErrorMessage = "Please enter Email")]
[RegularExpression(RegexTypes.EMAIL, ErrorMessage = RegexTypes.EMAIL_MESSAGE)]
public string Email { get; set; }
[DisplayName("Confirm Email")]
[Required(ErrorMessage = "Please re enter Email")]
[RegularExpression(RegexTypes.EMAIL, ErrorMessage = RegexTypes.CONFIRM_EMAIL_MESSAGE)]
[DataType(DataType.EmailAddress)]
[System.Web.Mvc.Compare("Email", ErrorMessage = "The email and confirmation email does not match.")]
public string ReEmail { get; set; }
它工作正常并显示消息。
如果电子邮件无效,我想停止用户,然后用户不应该能够在第二个文本框中输入确认电子邮件,直到电子邮件不正确。怎么做?有人请帮助我。