我正在爲我的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; }
它工作正常,並顯示該消息。
我想停止用戶,如果電子郵件是無效的,那麼用戶不應該能夠在第二個文本框中輸入確認電子郵件,直到電子郵件不正確。怎麼做?有人請幫助我。
什麼是regainFocusOnError()? – Rocky
你自己的js在.focus()函數中使用,最後可能是.select()。可以寫整個js行,雖然 – Max
讓我們說:onblur =「var me = this; setTimeout(function(){if(!isEmailValid()){me.focus();}},0);」 – Max