HTML5 provides an email domain name automatic assignment prompt for Input

Source: Internet
Author: User

Product Feedback users always enter the wrong email domain name, so the email address obtained by the server is incorrect. For example, there are many users who always input a xxx@qq.com into a xxx@qq.con.

This worries the backend, because the email address is legal, but the error is so obvious (I do not know whether the QQ. Con domain name exists ).

  

To solve this problem, I spent an hour in the afternoon using the new list attribute in HTML5 input. When the user inputs '@', the user is prompted with Domain Name Information. :

  

 

 

 

However, it was found that this property was not supported in Safari, and thus could not be supported in the app. It is estimated that it can only be used in chrome. It's just learning. The general idea is to listen to the user input '@', construct a datalist, and associate it with the input. Dependent on jquery.

 

(Function () {var emails = [{domain: '@ QQ.com', label: 'qq mailbox '}, {domain:' @ 163.com ', label: 'mailbox 163 '}, {domain:' @ 126.com ', label: 'mailbox 126'}, {domain: '@ hotmail.com', label: 'hotmail '}, {domain: '@ Sina.com', label: 'sina '}, {domain:' @ gmail.com ', label: 'gmail '}, {domain: '@ 139.com ', label: '2014 mailbox '}, {domain:' @ yahoo.com.cn ', label: 'yahoo China mailbox'}]; var addemailhelp = function (ID, otheraddress) {var I Nputobj = $ ('input # '+ id); If (inputobj. length = 0) {return;} inputobj. keyup (function (EV) {var val = $ (inputobj ). val (); var lastinputkey = Val. charat (Val. length-1); If (lastinputkey = '@') {var indexofat = Val. indexof ('@'); var username = Val. substring (0, indexofat); if ($ ('datalist # emaillist '). length> 0) {$ ('datalist # emaillist '). remove () ;}$ (inputobj ). parent (). append ('<datalist id = "EMA Illist "> </datalist> '); For (var I in emails) {$ ('datalist # emaillist '). append ('<option value = "' + username + emails [I]. domain + '"label ="' + emails [I]. label + '"/>');} If (otheraddress! = NULL & typeof otheraddress! = 'Undefined') {for (var I in otheraddress) {$ ('datalist # emaillist '). append ('<option value = "' + username + otheraddress [I]. domain + '"label ="' + otheraddress [I]. label + '"/>') ;}$ (inputobj ). ATTR ('LIST', 'emaillist') ;}}; window. addemailhelp = addemailhelp ;})();

 

You can set an ID for input and associate it with addemailhelp (ID, otheraddress). This function is already associated with some frequently used mailbox domain names by default.

Otheradress can be associated with other custom addresses. This parameter can be blank when a function is called.

An otheraddress instance: [{domain: '@ xxx.com', label: 'xxx mailbox '}, {domain:' @ yyy.com ', label: 'yyy mailbox'}].

 

A complete call instance:

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.