Customized HTML5 Form validations With Examples

input id="name" name="name" value="" required  pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="Sravan">
input type="email" id="email" name="email" value="" required aria-required="true">
input type="url" id="website" name="website" value="">
input type="number" id="numTickets" name="numTickets" value="" required aria-required="true" min="1" max="4">

7. INPUT patterns for different data types

URL input pattern:

input type="url" pattern="https?://.+"
IPv4 Address input pattern:

input type="text" pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
Date input pattern (dd/mm/yyyy or mm/dd/yyyy):

input type="text" pattern="\d{1,2}/\d{1,2}/\d{4}"
Price input pattern:

input type="text" pattern="\d+(\.\d{2})?"
Latitude/Longitude input pattern:

input type="text" pattern="-?\d{1,3}\.\d+"

Leave a Reply

Your email address will not be published. Required fields are marked *