使用jQuery验证电子邮件 [英] Validate email with jQuery
本文介绍了使用jQuery验证电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在页面上有 input name =email
和一个按钮
。
如何在有效的电子邮件地址中实时验证此输入?如果它是有效的或非活动的,则为按钮添加一些类,活动类。
这是一项小任务,所以我不想使用一个插件。
谢谢
解决方案
我通常使用这个javascript函数在前端验证:
function validateEmail(email)
{
var re = / ^(( [^<>()[\] \\;:\s @ \]。+(\ [^<>()[\] \\。 ;:\s @ \ ] +)*)|(\ + \))@((\ [[0-9] {1,3} \ [0-9。 ] {1,3} \ [0-9] {1,3} \ [0-9] {1,3} \])|。。(([A-ZA-Z\-O- 9] + \。)+ [a-zA-Z] {2,}))$ /
return email.match(re)
}
它返回true或false。
但无论如何,您通常不应该只验证前端中的敏感数据,还应该在服务器端验证。
I have input name="email"
and a button
on the page.
How do I validate this input in live for a valid email address? And add some class for a button, class "active" if it is valid or "inactive".
This is a small task, so I don't want to use a plugins.
Thanks
解决方案
I usually use this javascript function to validate in frontend:
function validateEmail(email)
{
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return email.match(re)
}
it returns true or false. But anyway, you shouldn't usually only validate sensitive data in the frontend, but also on the server side.
这篇关于使用jQuery验证电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文