JS Form Verification Code (commonly used) and js Form Verification Code

Source: Internet
Author: User
Tags valid email address

JS Form Verification Code (commonly used) and js Form Verification Code

There have been no projects recently, and there is a little time to do it. I will sort out the commonly used js Form Verification Code and share it with the help house platform for your reference!

Registration Verification:

<Script language = "JavaScript" src = "js/jquery-1.9.1.min.js" type = "text/javascript"> </script> // validate form function vailForm () {var form = jQuery ("# editForm"); if (! VailNickName () return; if (! VailPhone () return; if (! VailPwd () return; if (! VailConfirmPwd () return; if (! VailEmail () return; if (! VailCode () return; if (! VailAgree () return; form. submit () ;}// verify the nickName function vailNickName () {var nickName = jQuery ("# nickName "). val (); var flag = false; var message = ""; var patrn =/^ \ d + $/; var length = getNickNameLength (); if (nickName = '') {message =" nickName cannot be blank! ";} Else if (length <4 | length> 16) {message =" the nickname is 4-16 characters! ";} Else if (checkNickNameIsExist () {message =" this nickname already exists. Please enter it again! ";}Else {flag = true;} if (! Flag) {jQuery ("# nickNameDiv "). removeClass (). addClass ("ui-form-item has-error"); jQuery ("# nickNameP" ).html (""); jQuery ("# nickNameP" ).html ("<I class = \" icon-error ui-margin-right10 \ "> <\/I>" + message ); // jQuery ("# nickName "). focus ();} else {jQuery ("# nickNameDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# nickNameP" ).html (""); jQuery ("# nickNameP" developer.html ("<I class = \" icon-success ui-margin-right1 0 \ "> <\/I> this nickname is available");} return flag;} // calculate the nickname length function getNickNameLength () {var nickName = jQuery ("# nickName "). val (); var len = 0; for (var I = 0; I <nickName. length; I ++) {var a = nickName. charAt (I); // Function Format: stringObj. match (rgExp) stringObj is a string. It is required. rgExp is a required regular expression. // return value: if it can be matched, return the result array. If it cannot match, return nullif (. match (/[^ \ x00-\ xff]/ig )! = Null) {len + = 2;} else {len + = 1 ;}} return len ;}// verify whether the nickname has function checkNickNameIsExist () {var nickName = jQuery ("# nickName "). val (); var flag = false; jQuery. ajax ({url: "checkNickName? T = "+ (new Date ()). getTime (), data: {nickName: nickName}, dataType: "json", type: "GET", async: false, success: function (data) {var status = data. status; if (status = "1") {flag = true ;}}); return flag ;}// verify the mobile phone number function vailPhone () {var phone = jQuery ("# phone "). val (); var flag = false; var message = ""; // var myreg =/^ (13 [0-9] {1}) | 159 | 153) + \ d {8}) $/; var myreg =/^ (13 [0-9] {1}) | (14 [0-9] {1 }) | (17 [0-9] {1}) | (15 [0-3] {1 }) | (15 [5-9] {1}) | (18 [0-3] {1}) | (18 [5-9] {1 })) + \ d {8}) $/; if (phone = '') {message =" the mobile phone number cannot be blank! ";} Else if (phone. length! = 11) {message = "enter a valid mobile phone number! ";} Else if (! Myreg. test (phone) {message = "enter a valid mobile phone number! ";} Else if (checkPhoneIsExist () {message =" this phone number has been bound! ";}Else {flag = true;} if (! Flag) {jQuery ("# phoneDiv "). removeClass (). addClass ("ui-form-item has-error"); jQuery ("# phoneP" ).html (""); jQuery ("# phoneP" ).html ("<I class = \" icon-error ui-margin-right10 \ "> <\/I>" + message ); // jQuery ("# phone "). focus ();} else {jQuery ("# phoneDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# phoneP" ).html (""); jQuery ("# phoneP" developer.html ("<I class = \" icon-success ui-margin-right10 \ "> <\/I> this phone number is available ");} Return flag;} // verify whether the mobile phone number has function checkPhoneIsExist () {var phone = jQuery ("# phone "). val (); var flag = true; jQuery. ajax ({url: "checkPhone? T = "+ (new Date ()). getTime (), data: {phone: phone}, dataType: "json", type: "GET", async: false, success: function (data) {var status = data. status; if (status = "0") {flag = false ;}}); return flag ;}// verify the password function vailPwd () {var password = jQuery ("# password "). val (); var flag = false; var message = ""; var patrn =/^ \ d + $/; if (password = '') {message = "the password cannot be blank! ";} Else if (password. length <6 | password. length> 16) {message =" password 6-16 characters! ";} Else if (patrn. test (password) {message =" the password cannot be all numbers! ";}Else {flag = true;} if (! Flag) {jQuery ("# passwordDiv "). removeClass (). addClass ("ui-form-item has-error"); jQuery ("# passwordP" ).html (""); jQuery ("# passwordP" cmd.html ("<I class = \" icon-error ui-margin-right10 \ "> <\/I>" + message ); // jQuery ("# password "). focus ();} else {jQuery ("# passwordDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# passwordP" ).html (""); jQuery ("# passwordP" cmd.html ("<I class = \" icon-success ui-margin-right1 0 \ "> <\/I> the password is available");} return flag;} // verify and confirm the password function vailConfirmPwd () {var confirmPassword = jQuery ("# confirm_password "). val (); var patrn =/^ \ d + $/; var password = jQuery ("# password "). val (); var flag = false; var message = ""; if (confirmPassword = '') {message =" enter a confirmation password! ";} Else if (confirmPassword! = Password) {message = "the two passwords are inconsistent. Please enter them again! ";} Else if (patrn. test (password) {message =" the password cannot be all numbers! ";}Else {flag = true;} if (! Flag) {jQuery ("# confirmPasswordDiv "). removeClass (). addClass ("ui-form-item has-error"); jQuery ("# confirmPasswordP" ).html (""); jQuery ("# confirmPasswordP" example .html ("<I class = \" icon-error ui-margin-right10 \ "> <\/I>" + message ); // jQuery ("# confirm_password "). focus ();} else {jQuery ("# confirmPasswordDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# confirmPasswordP" ).html (""); jQuery ("# confirmPassword P "cmd.html (" <I class = \ "icon-success ui-margin-right10 \"> <\/I> correct password ");} return flag ;} // 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) {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 {jQuery ("# emailDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# emailP" ).html (""); jQuery ("# emailP" developer.html ("<I class = \" icon-success ui-margin-right10 \ "> <\/I> This mailbox is available");} re Turn flag;} // 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 ;}// verify the verification code function vailCode () {var randCode = jQuery ("# randCode "). val (); var flag = false; var message = ""; if (randCode = '') {message =" Enter the verification code! ";} Else if (! CheckCode () {message = "Incorrect verification code! ";}Else {flag = true;} if (! Flag) {jQuery ("# randCodeDiv "). removeClass (). addClass ("ui-form-item has-error"); jQuery ("# randCodeP" ).html (""); jQuery ("# randCodeP" developer.html ("<I class = \" icon-error ui-margin-right10 \ "> <\/I>" + message ); // jQuery ("# randCode "). focus ();} else {jQuery ("# randCodeDiv "). removeClass (). addClass ("ui-form-item has-success"); jQuery ("# randCodeP" ).html (""); jQuery ("# randCodeP" developer.html ("<I class = \" icon-success ui-margin-right1 0 \ "> <\/I>");} return flag;} // check whether the Random verification code is correct function checkCode () {var randCode = jQuery ("# randCode "). val (); var flag = false; jQuery. ajax ({url: "checkRandCode? T = "+ (new Date ()). getTime (), data: {randCode: randCode}, dataType: "json", type: "GET", async: false, success: function (data) {var status = data. status; if (status = "1") {flag = true ;}}); return flag ;}// determine whether function vailAgree () is selected () {if (jQuery ("# agree "). is (": checked") {return true;} else {alert ("please confirm whether to read and agree to the XX Protocol");} return false;} function delHtmlTag (str) {var str = str. replace (/<\/? [^>] *>/Gim, ""); // remove all html tags var result = str. replace (/(^ \ s +) | (\ s + $)/g, ""); // remove the leading and trailing spaces and return result. replace (// \ s/g, ""); // remove spaces in the middle of the article} <! DOCTYPE html> <body> 

The above code is a small series of JavaScript form verification, the code is simple and easy to understand, very practical, I hope to help you, but also thank you very much for your support for the help House website!

Articles you may be interested in:
  • Prototype-based validation. js releases version 2.3.4, which frees you from form verification.
  • Javascript Zifa FormValid 0.1 Form Verification code package download
  • Javascript code for real-time Form Verification
  • Collection of JavaScript form verification control code Daquan
  • Form Verification for js tomato
  • Js Form Verification Method (practical)
  • Regular Expressions for JavaScript form verification [recommended]
  • Sample Code for JavaScript Form Verification Using Regular Expressions
  • Javascript Regular Expression Form Verification Code
  • Javascript Form Verification
  • Javascript form verification-use and configuration of Parsley. js
  • The php user registration page uses js for form verification of specific instances
  • Simple js form verification functions
  • AngularJS implements Form Verification
  • Jquery Form Verification plug-in (jquery. validate. js)
  • Form Verification of simple registration module made by javascript
  • Complete example of General Form Verification plug-in implemented by JS

Related Article

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.