消除html5电子邮件验证器失去焦点,除了提交表单 [英] Fire html5 email validator on losing focus besides just on submission of forms

查看:171
本文介绍了消除html5电子邮件验证器失去焦点,除了提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子邮件输入字段,我会检查电子邮件是否已经存在于我的数据库中,使用ajax从该电子邮件输入中失去焦点。在进行ajax调用之前,我想确保输入的电子邮件格式正确。我可以使用html5内置电子邮件验证程序执行此操作,还是必须编写自己的验证函数?

I have an email input field where i check if the email is already present in my database using ajax on losing focus from that email input. I want to make sure the email entered is in the correct format before i make an ajax call. Can i do this with html5 built-in email validator or do i have to write my own validation function?

编辑:我已经在使用html5电子邮件验证程序,但它验证了只有在提交表单时才会发送电子邮件。

I am already using the html5 email validator but it validates the email only when the form is submitted.

推荐答案

在Firefox 中,应查看电子邮件默认情况下键入的有效性(原生HTML5行为):
http://jsfiddle.net/xs65r /

In Firefox, it should check the email for validity as you're typing by default (native HTML5 behavior): http://jsfiddle.net/xs65r/

但要支持所有HTML5浏览器,您需要手动调用 checkValidity() onblur 和/或 onkeydown

But to support all HTML5 browsers, you'll need to manually call checkValidity() onblur and/or onkeydown.

查看此链接更多细节:
HTML5 Chrome checkValidity onBlur

See this link for more detail: HTML5 Chrome checkValidity onBlur

正如您在下面的评论中所说,您必须在mab之前的onblur函数的if子句中使用this.checkValidity()函数进行ajax调用,并自行调度任何错误,因为在除Firefox以外的浏览器中,除非提交表单,否则不会触发本机验证消息UI。

As you said in your comment below, you have to use the function this.checkValidity() in an if clause in your onblur function before making the ajax call, and dispay any errors yourself, since in browsers other than Firefox the native validation message UI isn't triggered unless the form is submitted.

这篇关于消除html5电子邮件验证器失去焦点,除了提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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