The benefit of HTML5 validations is that they take minimal effort to implement. You add a few attributes to your markup and you're good to go. The downside is that it is still unsupported in some browsers. Depending on your needs, a lightweight solution like this may be enough.
HTML5 gives you a lot, from marking fields as required, to size limits, to ensuring emails look like emails. Here's a taste:
Mark a field as `required` with the `required` attribute:
<input name="name" type="text" required>
Ensure an email address is formatted correctly:
<input name="email" type="email">
Ensure a URL is formatted correctly:
<input name="email" type="url">
Ensure a number is with a range:
<input name="age" type="number" min="18" max="99" value="21">
You can also limit the characters in a text input or textarea:
<textarea name="bio" minlength="50" maxlength="300"></textarea>
Maybe you want to not allow certain email service providers. This will not allow gmail.com, hotmail.com or yahoo.com email addresses from being entered.
<input type="text" name="email" placeholder="work email" pattern="^((?!(gmail.com|hotmail.com|yahoo.com)).)*$" title="Work email addresses only">
That's it! Why not get started now?Create your form