使用Jquery.validate.js验证电子邮件地址的格式 [英] Validate Format of an Email Address using Jquery.validate.js
问题描述
我正在使用 jquery.validate.js 来验证公式编制器的电子邮件输入. /p>
它运作良好,但是我很惊讶它是有效的电子邮件,但格式如下:name @ domain
我认为缺少.TLD,不是吗?
我检查了jquery.validate.js文件中的功能.他们从 验证表单的功能如下: 我需要包括什么,所以脚本使用我的自定义方法而不是电子邮件方法? 尝试以下 I'm using jquery.validate.js to validate the Email Input of the Formular. It's working well, but I'm suprised that it's excepting emails as valid with the following format: name@domain In my opinion there is missing a .TLD, no? I checked the function inside the jquery.validate.js file. They are referencing the specification from www.whatwg.org for a valid email Adress. On the site it says that a valid email address should have the format name@doman.tld The JS Regex inside jquery.validate.js is the following: How do I use a custom Regex that validates if the email includes a .TLD? I specified the custom validation method as following: The function to validate the form is the following: What do I need to include, so the script uses my custom method instead of the email method? Try this
这篇关于使用Jquery.validate.js验证电子邮件地址的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!$("#subscription-form").validate({
});
Regex
:/^(([^<>()[\]\\.,;:\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,}))$/
email: function( value, element ) {
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
},
jQuery.validator.addMethod("customemail", function(value, element) {
return this.optional(element) || /^(([^<>()[\]\\.,;:\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,}))$/.test(value);
}, "Please enter a valid email address.");
$("#subscription-form").validate({
});
Regex
:/^(([^<>()[\]\\.,;:\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,}))$/