Introduction
The pattern attributes is used to make customized textbox that accepts input in predefined format. Although there is input type which accept certain input type like email, URL, date, time etc. But it is used for making a more customized input field. Suppose we want a
textbox that accepts only ten-digit for phone number. We will write the below
code:
- <!DOCTYPE HTML>
- <html>
- <body>
- <form method="post">
- Phone Number
- <input type="text" pattern="[0-9]{10}" title="Ten Digit Number" />
- <input type="submit" />
- </form>
- </body>
- </html>
Output will look like below figure:
Here, we note that when input length is not equal to ten, then it shows a message with the title 'Ten Digit Number' on button click. Like as below
figure