
- 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
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>
- Related Articles
- HTML pattern Attribute
- How to use autocomplete attribute in HTML?
- How to use formnovalidate attribute in HTML?
- How to use formaction attribute in HTML?
- How to use formenctype attribute in HTML?
- How to use formtarget attribute in HTML?
- How to use multiple attribute in HTML?
- How to use placeholder attribute in HTML?
- How to use step attribute in HTML?
- How to use href attribute in HTML Page?
- How to use a novalidate attribute in HTML?
- How to use the formmethod attribute in HTML?
- How to use the required attribute in HTML?
- How to use image height and width attribute in HTML Page?
- How to use different step attribute in one range input in HTML?

Advertisements