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
docker-compose-monitor.yml version: '2' n...
Table label composition The table in HTML is comp...
First, let’s think about a question: To insert su...
Table of contents 1. Operation of js integer 2. R...
1. Nginx status monitoring Nginx provides a built...
Table of contents Examples from real life Slow qu...
1. Using Selenium in Linux 1. Install Chrome Inst...
The official document states: By injecting the ro...
1. Overview Zabbix is a very powerful and most ...
Database backup #grammar: # mysqldump -h server-u...
The following example code introduces the princip...
Method 1: Use cmd command First, open our DOS win...
Demand background The project is made using Vue, ...
Table of contents Avoid using the spread operator...
Service.xml The Server.xml configuration file is ...