Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JQUERY to write registration verification

Shulou Source: shulou.com Published: 2022-06-03 03:53:13 10月18日 Update

This article will explain in detail how to use JQUERY to write registration verification. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1 compatible with IE678

2 suitable for website development

Html:

$(function () {)

/ / user name loses focus

$("# userName"). On ("keyup blur", function () {

UserNameCheck ()

});

/ / the password loses focus

$("# pwd"). On ("keyup blur", function () {

PwdCheck ()

});

/ / confirm that the password is out of focus

$("# pwdConfirm"). On ("keyup blur", function () {

PwdConfirmCheck ()

});

/ / the mailbox loses focus

$("# email"). On ("keyup blur", function () {

EmailCheck ()

});

/ / submit

$("# reg") .click (function () {

If (userNameCheck ()) = = false | | pwdCheck () = = false | | pwdConfirmCheck () = = false | | emailCheck () = = false)

{

/ / alert ("check form")

Return

}

Else {

$.ajax ({

Type: "post"

Url: "Submit.aspx"

Data: $(form) .serialize ()

Success: function (response,status,xhr) {

If (response== "success")

{

Alert ("Registration successful!")

_ window.location = "HtmlPage1.html"

}

Else {

Alert ("Registration failed!")

}

}

Error: function () {

Alert ("ajax error")

}

});

}

});

$(document) .ajaxStart (function () {

("# div1") .show ()

}) .ajaxStop (function () {

("# div1") .hide ()

});

});

/ / verify the mailbox format

Function checkEmail (str) {

Var re = / ^ (\ wmurf *) + @ (\ wmurf?) + (\.\ w {2,}) + $/

If (re.test (str)) {

Return true

}

Else {

Return false

}

}

Function userNameCheck () {

Var userName = $("# userName") .val ()

/ / user name cannot be empty

If (userName = "") {

$("# label_UserName") .html ("user name cannot be empty!")

/ / $("# userName") [0] .focus ()

Return false

}

Else {

$.ajax ({

Type: "post"

Url: "Ajax.aspx"

Data: $.param ({userName: $("# userName") .val ()})

Success: function (response, status, xhr) {

If (response = = "ok") {

("# label_UserName"). Html ('

')

Return true

}

Else {

$("# label_UserName") .html ("user name already exists!")

Return false

}

}

});

}

}

Function pwdCheck () {

Var pwd = $("# pwd") .val ()

If (pwd = "") {

$("# lable_pwd") .html ("password cannot be empty!")

/ / $("# pwd") [0] .focus ()

Return false

}

Else {

If (pwd.length

< 6) { $("#lable_pwd").html("密码不能少于6位!"); return false; } else { $("#lable_pwd").html('

')

Return true

}

}

}

Function pwdConfirmCheck () {

Var pwdConfirm = $("# pwdConfirm") .val ()

If (pwdConfirm = "") {

$("# label_pwdConfirm") .html ('confirm password cannot be empty!')

Return false

}

Else {

If ($("# pwdConfirm") .val ()! = $("# pwd") .val ()) {

$("# label_pwdConfirm") .html ('the password entered twice is not the same, please re-enter it!')

Return false

}

Else {

("# label_pwdConfirm"). Html ('

')

Return true

}

}

}

Function emailCheck () {

Var email = $("# email") .val ()

If (email = "") {

$("# label_email") .html ('mailbox cannot be empty!')

Return false

}

Else {

If (checkEmail (email) = = false) {

$("# label_email") .html ('incorrect mailbox format!')

Return false

}

Else {

("# label_email"). Html ('

')

Return true

}

}

}

# div1 {

Width: 180px

Height: 140px

Display: none

Font-weight: bold

Color: red

}

User name:

*

Password:

*

Confirm password:

*

Mailbox:

*

It is being submitted. Please wait a moment.

On "how to use JQUERY to write registration verification" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Password user name mailbox focus authentication article more format input good practical consistent success content article knowledge website website development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Linux Shulou Information MariaDB