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 ){}}