HTML5 form validation

HTML5 form validation, validating forms in HTML5 is simple and easy just add the attributes to input fields, they will take care of validations. First what we need most is making a field mandatory for that we can just use an attribute to any type of input fields that is required attribute. And the next one is for validating email addresses, for this we can use email input type. And for validating URL’s we can use input type url. And still there are many more.

HTML5 form validation

Making a field Mandatory in HTML5

First one is for making a input field mandatory we will use required attribute for any input type field.

used it for normal input type text field.
[html] <input type="text" name="firstname" required >

We can add just required or else we can use required=”required”

[html] <input type="text" name="firstname" required="required">

And we can use this attribute for any input type field.

Validating email address in HTML5

And next one is validating email addresses, for this we can use input type email.

[html] <input type="email" name="email">

For making this email as required field just add attribute of required to this field.

[html] <input type="email" name="email" required >

or else you can add like this

[html] <input type="email" name="email" required="required" >

Validating url’s in HTML5

For validating url’s in HTML5, just use input field type url

[html] <input type="url" name="website">

for making this mandatory
[html] <input type="url" name="website" required>

or else we can use this code also

[html] <input type="url" name="website" required="required" >

This is simple usage of HTML5 form validations we can use them for other advanced features.

Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.