This article shares the specific code of JavaScript to achieve random generation of verification codes and verification for your reference. The specific content is as follows Enter the verification code (case sensitive) and click Confirm to verify. Pop-up window prompts when an error occurs Click to regenerate a random verification code Prompt when the verification code is entered incorrectly <body> <div class="v_code"> <div class="code_show"> <span class="code" id="checkCode"></span> <a href="#" id="linkbt">Can't see clearly, change one</a> </div> <div class="input_code"> <label for="inputCode">Verification code:</label> <input type="text" id="inputCode"> <span id="text_show"></span> </div> <input type="button" id="Button1" value="Confirm"> </div> <script> // 1. Generate verification code // 6 digits 0-9 af Randomly generate 6 digits must be 0-9 af string // Array subscript 0, 1, 2... Randomly subscript 0-15 from the array // 2. Verify and click Confirm to compare window.onload = function() { const randomWord = () => { let code = ''; for (var i = 0; i < 6; i++) { var type = getRandom(1,3); switch(type) { case 1: code += String.fromCharCode(getRandom(48,57)) // digital break; case 2: code += String.fromCharCode(getRandom(65,90)); //capital break; case 3: code += String.fromCharCode(getRandom(97,122)); //lowercase letter break; } } return code; } function getRandom(min, max) { return Math.round(Math.random()*(max-min)+min) } //Call the data retrieval function const rand = randomWord(); //console.log(rand); var checkCode = document.getElementById('checkCode'); checkCode.innerText = rand; // Click to switch random number var linkbt = document.getElementById('linkbt'); linkbt.addEventListener('click', function() { checkCode.innerText = randomWord(); }) // Submit for comparison document.getElementById('Button1').onclick = function() { var inputCode = document.querySelector('#inputCode'); if (inputCode.value != checkCode.innerText) { alert('The verification code you entered is incorrect'); inputCode.value = ''; return false; } else { alert('Input is correct'); } } } </script> </body> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Docker Compose network settings explained
>>: Mysql Workbench query mysql database method
There are many articles about ssh server configur...
At the beginning of this article, I would like to ...
An absolute URL is used to represent all the conte...
There has been a lot of discussion about H1 recent...
Tip: In MySQL, we often need to create and delete...
This article uses examples to illustrate the MySQ...
Step 1. Enable MySQL slow query Method 1: Modify ...
Linux builds NFS server In order to achieve data ...
1. What are CSS methodologies? CSS methodologies ...
It is not possible to use width and height directl...
1. MS SQL SERVER 2005 --1. Clear the log exec(...
Correspondence between flutter and css in shadow ...
Table of contents Prototype chain We can implemen...
One day I found that the execution speed of a SQL...
Environment Preparation Before starting any opera...