Verification of mobile phone verification codes

Source: Internet
Author: User
When registering a user, you need to enter some content to give each form a flag value. when the focus is lost and the flag value of the form is finally submitted, these flag values are correct, can be submitted, but the problem arises: if the current user's focus is in the verification code input box, the user enters the verification... when registering a user, you need to enter some content to give each form a flag value.
When the focus is lost, the flag value of the form is detected.
These flag values are correct before submission.
But the problem is:
If the current user's focus is in the verification code input box, after entering the verification code, the user clicks the submit button to register, no problem
Because the user moves the mouse from the verification code input box to the submit button, the verification of the verification code has been completed, and its flag value is already true
However, if the user uses the enter key for submission and the focus is still in the verification code input box, you need to manually use the code under focusout ().

$("input:focus").focusout();for(var i=0;i<$("input").length;i++){    if($("input").eq(i).attr('flag')==0){        return false;    }}

The verification code is placed in the session. at this time, check whether the user's verification code is correct in the background. the flag value of the form is still false, and the following code is executed, return false indicates that the form cannot be submitted.
I also thought about a latency for the for loop, so that when the user submits, the verification can be completed.
However, in this case, the user can directly submit without entering anything, and all the verification at the front-end will be voided.
I don't know if my description is clear enough. if you have any questions, leave a message. thank you.

Reply content:

When registering a user, you need to enter some content to give each form a flag value.
When the focus is lost, the flag value of the form is detected.
These flag values are correct before submission.
But the problem is:
If the current user's focus is in the verification code input box, after entering the verification code, the user clicks the submit button to register, no problem
Because the user moves the mouse from the verification code input box to the submit button, the verification of the verification code has been completed, and its flag value is already true
However, if the user uses the enter key for submission and the focus is still in the verification code input box, you need to manually use the code under focusout ().

$("input:focus").focusout();for(var i=0;i<$("input").length;i++){    if($("input").eq(i).attr('flag')==0){        return false;    }}

The verification code is placed in the session. at this time, check whether the user's verification code is correct in the background. the flag value of the form is still false, and the following code is executed, return false indicates that the form cannot be submitted.
I also thought about a latency for the for loop, so that when the user submits, the verification can be completed.
However, in this case, the user can directly submit without entering anything, and all the verification at the front-end will be voided.
I don't know if my description is clear enough. if you have any questions, leave a message. thank you.

You can execute all the test conditions when you are about to submit them, and check whether all the flag is true.

You can directly submit the verification code input value to compare with the background session. why do you need to submit a front-end verification mark? All the content submitted by the front-end can be forged.

Add an ajax event before you submit, that is, determine whether the verification code is correct and submit again. if the verification code is incorrect, a window pops up and you do not submit it.
The above situation can be prevented.

$ ("Input [type = submit]"). click (function () {$ ("input: focus "). focusout (); // detection latency about 50 s setTimeout (function () {var submitFlag = true; // Two for loops can extract a function for (var I = 0; I <$ ("input "). length-2; I ++) {if ($ ("input "). eq (I ). attr ('flag') = 0) {submitFlag = false ;}} if (submitFlag) {$ ("form "). submit () ;}}, 100); for (var I = 0; I <$ ("input "). length-2; I ++) {if ($ ("input "). eq (I ). attr ('flag') = 0) {return false ;}}});

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.