How to use js for form Verification in php user Registration Page
This article mainly introduces the php user registration page how to use js for form verification, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The code is as follows:
User Registration-
Var flag = {
"email": false
"nickname": false
"password": false
"verify": false
}
$(function () {)
$("# txtEmail") .blur (function () {
Var email=$ (this) .val ()
/ / alert (email)
If (email== "") {
$("# email\\ .info") .html ("Email address cannot be empty")
Return
}
Var pattern=/\ b (^ ['_ A-Za-z0-9 -] + (\. ['_ A-Za-z0-9 -] +) * @ ([A-Za-z0-9 -]) + (\. [A-Za-z0-9] +) * ((\. [A-Za-z0-9] {2,}) | (\. [A-Za-z0-9] {2,}) $)\ b /
If (! pattern.test (email)) {
$("# email\\ .info") .html ("Email format is incorrect")
Return
}
Get ("check_email.php?email=" + email,null)
Function (data) {
$("# email\\ .info") .html (data)
If (data== "can register") {
Flag.email=true
}
}
);
});
$("# txtNickName") .blur (function () {
Var nickname=$ (this) .val ()
If (nickname== "") {
$("# name\\ .info") .html ("nickname cannot be empty")
Return
}
Var pattern = /\ b (^ ['A-Za-z0-9] {4pm 20} $)\ b /
If (! pattern.test (nickname)) {
$("# name\\ .info") .html ("nickname format is incorrect")
Return
} else {
$("# name\\ .info") .html ("nickname format is correct")
Flag.nickname=true
Return
}
});
$("# txtPassword") .blur (function () {
Var password=$ (this) .val ()
If (password== "") {
$("# password\\ .info") .html ("password cannot be empty")
Return
}
Var pattern = /\ b (^ ['A-Za-z0-9] {4pm 20} $)\ b /
If (! pattern.test (password)) {
$("# password\\ .info") .html ("password format is incorrect")
Return
} else {
$("# password\\ .info") .html ("password format is correct")
/ / flag.password=true
Return
}
});
$("# txtRepeatPass") .blur (function () {
Var password1=$ (this) .val ()
If (password1== "") {
$("# password1\\ .info") .html ("password cannot be empty")
Return
}
Var pattern = /\ b (^ ['A-Za-z0-9] {4pm 20} $)\ b /
If (! pattern.test (password1)) {
$("# password1\\ .info") .html ("password format is incorrect")
Return
} else if (password1encrypted $("# txtPassword") .val ()) {
$("# password1\\ .info") .html ("the passwords entered are not the same")
Return
} else {
$("# password1\\ .info") .html ("duplicate password is correct")
Flag.password=true
Return
}
});
$("# txtVerifyCode") .blur (function () {
Var verify=$ (this) .val ()
If (verify== "") {
$("# number\\ .info") .html ("CAPTCHA cannot be empty")
Return
}
$.post (". / verify/check.php", {verify:verify}
Function (data) {
$("# number\\ .info") .html (data)
If (data== "Verification successful") {
Flag.verify=true
}
}
);
})
$("# f") .submit (function () {
Var ok = flag.email&&flag.password&&flag.verify&&flag.nickname
If (ok==false) {
Alert ("form item is being detected or has an error")
History.back ()
Return false
}
Return true
});
})
Registration steps: 1. Fill in the information > 2. Verify mailbox > 3. Registered successfully
The following are required
Please fill in your Email address:
Please fill in a valid Email address.
Set your nickname:
It is composed of lowercase English letters, Chinese characters and numbers, with a length of 4mi 20 characters and a Chinese character of two characters.
Set the password:
Your password can be made up of uppercase and lowercase letters and numbers with a length of 6mi 20 digits.
Enter the password you set again:
CAPTCHA:
can't see clearly? Change the picture.
Thank you for reading this article carefully. I hope the article "how to use js for form verification on the php user registration page" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!