Jquery practice case -- verify email address and jquery case

Source: Internet
Author: User
Tags valid email address subdomain

Jquery practice case -- verify email address and jquery case

<Input type = "email" name = "email" id = "email" value = "" onpaste = "return false"/>

 

Let's take a look at all the mailboxes:

 

It is obviously impossible for us to make judgments by email address.

 

-A complete Internet email address consists of the following two parts: Logon Name @ host name. in the middle of the domain name, separate the "@" symbol indicating "at" (at). The left side of the symbol is the login name of the other party, and the right side is the complete host name, which consists of the Host Name and domain name. A domain name consists of several parts. Each part is called a Subdomain. each Subdomain is separated by a dot (.). Each Subdomain will tell you information about this email server.

 

Key validation Regular Expression: var myreg =/^ ([\. a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + (\. [a-zA-Z0-9 _-]) + /;

 

Check input box:

// Verify the email function vailEmail () {var email = jQuery ("# email "). val (); var flag = false; var message = ""; var myreg =/^ ([\. a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + (\. [a-zA-Z0-9 _-]) +/; if (email = '') {message =" Mailbox cannot be blank! ";} Else if (! Myreg. test (email) {message = "enter a valid email address! ";} Else if (checkEmailIsExist () {message =" this email address has been registered! ";}Else {flag = true;} if (! Flag ){
// Error message // jQuery ("# emailDiv "). removeClass (). addClass ("ui-form-item has-error"); // jQuery ("# emailP" ).html (""); // jQuery ("# emailP" example .html ("<I class = \" icon-error ui-margin-right10 \ "> & nbsp; <\/I>" + message ); // jQuery ("# email "). focus ();} else {
// Correct prompt // jQuery ("# emailDiv "). removeClass (). addClass ("ui-form-item has-success"); // jQuery ("# emailP" ).html (""); // jQuery ("# emailP" developer.html ("<I class = \" icon-success ui-margin-right10 \ "> & nbsp; <\/I> This mailbox is available ");} return flag ;}

 

Write a method to verify it

 

// Verify whether the email address has function checkEmailIsExist () {var email = jQuery ("# email "). val (); var flag = false; jQuery. ajax ({url: "checkEmail? T = "+ (new Date ()). getTime (), data: {email: email}, dataType: "json", type: "GET", async: false, success: function (data) {var status = data. status; if (status = "1") {flag = true ;}}); return flag ;}

 

Background processing program:

 

@ RequestMapping (value = "/checkEmail", method = RequestMethod. GET) public void checkEmail (HttpServletRequest request, HttpServletResponse response) {Map <String, Object> map = new HashMap <String, Object> (); try {String email = request. getParameter ("email"); String status = "0"; // write a query statement to check whether the email address exists in the table.
// UserBaseInfo userBaseInfo = userService. findUserByEmail (email );
// If (userBaseInfo! = Null) status = "1"; map. put ("status", status); String data = JSONObject. fromObject (map ). toString (); response. getWriter (). print (data); response. getWriter (). flush (); response. getWriter (). close () ;}catch (Exception ex ){}}

 

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.