- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use pattern attribute in HTML?
The pattern attribute in HTML is used to set a regular expression in the following input types: text, url, tel, search, date, email, and password. For passwords, with the pattern attribute, you can set the minimum required values. For example, password should have at least 8 characters.
Example
You can try to run the following code to learn how to use pattern attribute in HTML. Here, we have set the pattern for 8 or more characters in the password. If a user will add less than that, then by clicking Submit button, an error will raise i.e. “Please match the requested format: Eight or more characters”.
<!DOCTYPE html> <html> <body> <h2>Register</h2> <form action="/new.php"> Student UserName<br><input type = "text" name = "name"/><br> Password<br><input type = "password" name = "password" pattern = ".{8,}" title="Eight or more characters"><br><br> <input type = "submit" value = "Submit"> </form> </body> </html>
Advertisements