In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how JavaScript to achieve password box input verification, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Sometimes it is necessary to do simple verification on the front-end page when the user enters it, so as to reduce the pressure on the server.
For example, the input length of the field is limited:
There is a prompt for input range after the input box.
If you enter the wrong length, it becomes an error message.
If you enter the correct length, display the correct prompt message
Realization idea
1. Write out the input prompt first
2. Define the wrong and correct classes and write the corresponding style
3. Get the element object of the input box, judge the length of the attribute value by the if statement, display different prompt contents according to different results, and set different prompt class names---to switch styles.
Sample code password box input prompt div {width: 600px; margin: 100px auto;} input {outline: none;} .message {display: inline-block; font-size: 12px; color: # 999 Background: url (images/ prompt .png) no-repeat left center/16px 16px; padding-left: 20px;} .notify {background-image: url (images/ error .png); color: red;} .right {background-image: url (images/ correct .png); color: green } Please enter the 818-digit password
Var password = document.querySelector ('.inp'); var message = document.querySelector ('.message'); password.onblur = function () {if (this.value.length)
< 8 || this.value.length >18) {message [XSS _ clean] = 'password length error, should be 8' 18 bits'; message.className = 'message wrong';} else {message [XSS _ clean] =' password length is correct'; message.className = 'message right';}}
Page effect:
The above is all the contents of the article "how to implement password box input verification in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.