开发者

Why does the jQuery validate email regex allow emails ending in "."

We love jQuery validate, and really want 开发者_JAVA技巧to keep using it.

However, one of it's most useful features is to be able to validate email addresses client-side... but the regular expression that it uses accepts emails ending in ".", which I didn't believe was valid and certainly isn't liked by our back-end systems.

I wonder if anyone knows why this particular regex was chosen or whether it is perhaps a bug?

The jquery.validate-1.8.1 code in quesion:

        // http://docs.jquery.com/Plugins/Validation/Methods/email
    email: function(value, element) {
        // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
        return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
    },


stackoverflow.com. is perfectly valid - actually it's the only way to make a domain name a Fully Qualified Domain Name. Technically, it's your back-end systems that are at fault for not accepting this (although I'm sure I myself have written validation code in the past that doesn't accept it either...)

See http://www.dns-sd.org/TrailingDotsInDomainNames.html for an in-depth explanation.


I think this page will explain why the dot is allowed at the end:

http://en.wikipedia.org/wiki/Fully_qualified_domain_name

A fully qualified domain name (FQDN), sometimes also referred as absolute domain name,[1] is a domain name that specifies its exact location in the tree hierarchy of the Domain Name System (DNS). It specifies all domain levels, including the top-level domain and the root domain. A fully qualified domain name is distinguished by its unambiguity; it can only be interpreted one way.

For example, given a device with a local hostname myhost and a parent domain name example.com, the fully qualified domain name is myhost.example.com. The FQDN therefore uniquely identifies the device —while there may be many hosts in the world called myhost, there can only be one myhost.example.com. In the Domain Name System, and most notably, in DNS zone files, a fully qualified domain name is specified with a trailing dot. For example, somehost.example.com. specifies an absolute domain name that ends with an empty top level domain label.

The DNS root domain is unnamed, which is expressed by an empty label, resulting in a domain name ending with the dot separator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜