
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML pattern Attribute
The HTML pattern attribute define a regular expression against which the <input> HTML element’s value is matched in an HTML document.
Syntax
Following is the syntax −
<input pattern=”regular expression”>
Let us see an example of HTML pattern Attribute −
Example
<!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat; text-align: center; } input[type='password'] { width: 300px; padding: 8px 16px; border: 2px solid #fff; background: transparent; border-radius: 20px; display: block; margin: 1rem auto; outline: none; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 20px; width: 330px; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem auto; } ::placeholder { color: #000; } </style> <body> <h1>HTML pattern attribute Example</h1> <form action=""> <input type="password" placeholder="Enter your account password" required pattern=".{8,}"> <input type="submit" value="Submit" class="btn" onclick='check()'> </form> <div class="show"></div> <script> function check() { if (document.querySelector("input[type='password']").value.length < 8) { document.querySelector(".show").innerHTML = 'Please enter a password of more than or equal to 8 characters.' }; } </script> </body> </html>
Output
Enter a password which is less than 8 characters and then click on “Submit” button to show warning message.
- Related Articles
- How to use pattern attribute in HTML?
- HTML novalidate Attribute
- HTML maxlength Attribute
- HTML wrap Attribute
- HTML disabled Attribute
- HTML for Attribute
- HTML min Attribute
- HTML disabled Attribute
- HTML disabled Attribute
- HTML min Attribute
- HTML draggable Attribute
- HTML href Attribute
- HTML max Attribute
- HTML enctype Attribute
- HTML for Attribute

Advertisements