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. Best Ui/ux Design Company In New DelhiAuthor: globalsolutionit
2. Expert Email Marketing Services To Boost Your Business Growth
Author: Brightara Media
3. Why Choose Seo-friendly Dental Website Design Services Today?
Author: PSM Canada
4. Top Benefits Of Hiring A Professional Website Designing Company
Author: FODUU
5. Building A Strong Alumni Network With Alumni Management Software
Author: E2S Team
6. Website Maintenance Service In Singapore: Keeping Your Website Secure And Efficient
Author: Website Maintenance Service in Singapore
7. Professional Web Design & Development Services For Your Business
Author: Brightara Media
8. Key Benefits Of Choosing A Website Designing Company
Author: Liam Mackie
9. Seo Vs Smo: What’s The Difference?
Author: Brightara Media
10. Boost Your Business With Social Media Marketing And Website Design Services In Pune
Author: digitaldoraemon
11. Shopify Website Design Company – Visioninfotech
Author: visioninfotech
12. Enhance Your Brand With A Graphic Design Company In Delhi
Author: Kliff Technologies
13. Harnessing Ai For Seo
Author: Brightara Media
14. Utility Mapping Services Vs. Utility Conversion Services: Where Gis Mapping Fits In
Author: Mukul Barma
15. Multiply Your Roi With Professional Point Cloud To Cad And Gis Services
Author: Mukul Barma