ALL >> Web-Design >> View Article
How To Set Custom Validation Error Messages In Html5

If you have been working with HTML5 you might have definitely come across Validation Error Messages. While some developers still want to stay away from making use of validation forms it isn’t quite a clever idea as this helps in saving server-side resources and improve the performance of website or application. When you are talking of a large website every bit of performance counts and hence you can make no compromise. If every bit of information need to be validated from the server this will make your website crawl which is never desired.
One of the reasons many developers stay away from validation error messaging is the fact that they don’t seem to make out much out of it. Depending on the browser you are using these error messages might even be in incorrect languages creating confusion in the minds of the developers. At times these error messages also spoil the user experience and raise a lot of issue with cross-browser compatibility. To get round this problem you can set custom validation error messages for HTML5.
Let us take a look at a common example for an HTML5 validation error message. The API for ...
... the following would be something like.
element.oninvalid = function(e) {
if (!e.target.validity.valid) {
e.target.setCustomValidity("This field contains errors");
}
};
element.oninput = function(e) {
e.target.setCustomValidity("");
};
You will find the above example to be pretty confusing and following such kind of error messages you will end up writing lots of unnecessary JavaScript. There is another important thing that is missing in this error message – it doesn’t contain the logic for different states of error. It is in this kind of situations that creating a Custom Input Validation Error Messages becomes necessary. You can easily set the custom message by using data-errormessage and data-errormessage-* attributes on your form elements. Let us take a look at an example for such custom validation.
Data attribute naming format: data-val-{method name}
Data attribute naming example: data-val-required
Example:
So for the above example the HTML code will appear something like –
In the above example you can clearly see how we have set a custom validation error message to meet our needs and be cross browser compatible.
If you want to Hire HTML programmer for setting custom validation error messages in HTML5? Contact one of the most reputed PSD to HTML5 conversion company “MarkupBox
Add Comment
Web Design Articles
1. How To Choose The Right Website Packages For Small Business: A Budget Vs. Features ComparisonAuthor: Nishant Desai
2. Shopify And Wordpress Finally Join Forces: What This Means For The Future Of Online Stores
Author: Matthew John
3. Website Development Company: Choosing The Right Partner To Build Your Online Presence
Author: MSM CoreTech Innovations
4. Best Social Bookmarking Sites & Ideas For Better Website Visibility
Author: Brightara Media
5. Ruby On Rails: The Ultimate Framework For Building Web Applications Quickly
Author: Andy
6. Mt Marketingbureau Positioneert Zich Als Toonaangevend Webdesign Bedrijf En Expert In Wordpress Ondersteuning
Author: Olivia Bakker
7. How Student Wellbeing Software Is Revolutionising Campus Support
Author: E2S Team
8. Web Design 2.0: The Impact Of Artificial Intelligence On Digital Marketing
Author: Vikram kumar
9. What To Look For In A Creative Agency In San Diego
Author: Storm Brain
10. Crafting Digital Excellence: Your Premier Web Design Company In Bhopal
Author: ashish yadav
11. Web Design In Grande Prairie – Build A Website That Works For You
Author: Nathan Ava
12. Seo In Grande Prairie – Boost Your Business Visibility Online
Author: Nathan Ava
13. How Ai Is Improving Ux/ui Design In 2025: Smarter, Faster, And More Personalized Experiences
Author: ehawkers
14. Flutter App Development Company In Hyderabad | Conquerors Tech
Author: conquerors
15. Why Is A Curve Finance Clone Script The Best Way For Enterprenuers To Build Your Own Defi Exchange?
Author: Peterparker