jquery verifies that the mailbox format is correct example explain _jquery

Source: Internet
Author: User
Tags valid email address subdomain

Let's see what mailboxes are available:

It is obviously impossible for us to judge each of our mailboxes.
-A complete Internet mail address consists of the following two sections in the format: login @ host name. Domain Name
The middle is separated by a symbol "@" representing "at", and the left side of the symbol is the other's login name, and the right is the complete host name, which consists of the host name and the domain name. Among them, the domain name consists of several parts, each part is called a subdomain (subdomain), each subdomain uses the dot "." Separated, each subdomain tells the user some information about the mail server.
Key-Validated regular expressions: var myreg =/^ ([\.a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (\.[ A-za-z0-9_-]) +/;
Verify input box:

 Verify mailbox 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 empty!
       "; }else if (!myreg.test (email)) {message = "Please enter a valid email address!"
       "; }else if (checkemailisexist ()) {message = "This email address has already been registered!"
       ";
       }else{flag = true;
         } if (!flag) {//Error prompt//jquery ("#emailDiv"). Removeclass (). addclass ("Ui-form-item has-error");
         JQuery ("#emailP"). HTML ("");
         JQuery ("#emailP"). HTML ("<i class=\" Icon-error ui-margin-right10\ "> <\/i>" +message);
       JQuery ("#email"). focus ();
         }else{//correct prompt//jquery ("#emailDiv"). Removeclass (). addclass ("Ui-form-item has-success");
         JQuery ("#emailP"). HTML (""); JQuery ("#emailP"). HTML ("<i class=\" icon-success ui-margin-right10\ "> <\/i> The mailbox is available ");
     return flag; }

Write a way to verify

 Verify that the mailbox exists a
     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 handler:

@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 query statement, query table whether there is the mailbox
      //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) {
      
    }
  }

That's jquery. Verify that the mailbox format is the correct instance code, using regular expressions:var myreg =/^ ([\.a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (\.[ A-za-z0-9_-]) +/, we can try.

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.