如何在mvc中使用javascript电子邮件验证功能? [英] How to use javascript email validation function in mvc?

查看:94
本文介绍了如何在mvc中使用javascript电子邮件验证功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

I am having below javascript function-

function validateEmail(email)
{ 
var regx = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
if (reg.test(email)) {
return true; }
else {
return false;
}
}

I am using this function for validating an email.

I have below MVC view code-

 @Html.TextBoxFor(model => model.CustomField, new { maxlength = "51", @id = "TextBox1", onblur = ???? })

How i call this function into @Html.TextBoxFor, where it will allow to accept my input value?

Please suggest.

推荐答案

你可以使用mvc unobtrusive验证这个



http: //stackoverflow.com/questions/16712043/email-address-validation-using-asp-net-mvc-data-type-attributes [ ^ ]



http ://stackoverflow.com/questions/8538082/asp-net-mvc-3-required-steps-for-unobtrusive-client-side-validation-of-dynamic [ ^ ]



http://www.asp.net/mvc/overview/older-versions/creating-a-mvc-3-application-with-razor-and-unobtrusive- javascript [ ^ ]



您还可以获得服务器端验证的优势。
You can use the mvc unobtrusive validation for this

http://stackoverflow.com/questions/16712043/email-address-validation-using-asp-net-mvc-data-type-attributes[^]

http://stackoverflow.com/questions/8538082/asp-net-mvc-3-required-steps-for-unobtrusive-client-side-validation-of-dynamic[^]

http://www.asp.net/mvc/overview/older-versions/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript[^]

The advantage being you get server-side validation also.


这篇关于如何在mvc中使用javascript电子邮件验证功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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