123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Web-Design >> View Article

How To Set Custom Validation Error Messages In Html5

Profile Picture
By Author: imark ross
Total Articles: 21
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

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

Total Views: 357Word Count: 423See All articles From Author

Add Comment

Web Design Articles

1. Dark Mode, Light Speed: Modern Ux Trends In Web Development
Author: Suganya, Digital Marketing Intern.

2. Seo Service On A Low Budget With Brightara Media
Author: Brightara Media

3. New Technologies Booming In Mobile App Development
Author: Levontehcno

4. The Top Benefits Of Partnering With A Good Seo Company
Author: Liam Mackie

5. Why Choosing The Right Software Development Company In Delhi Can Boost Your Business
Author: Vikki kumar

6. Why Enseur Is A Top Event Management App For Modern Planners
Author: Enseur Tech

7. Customizable Web-based Erp Software In Noida Designed For Schools And Colleges
Author: CONTENT EDITOR FOR SAMPHIRE IT SOLUTIONS PVT LTD

8. How Custom Websites Drive Smarter Lead Generation And Crm Efficiency
Author: Wise Code Studio

9. Advanced Mobile Tracking Sg | Attendance 1 Sgd Monthly
Author: chinni jyothi

10. Employee Attendance Sg | Biometric Scanner 1 Sgd Per Month
Author: chinni jyothi

11. Top Seo Services In Delhi For Business Growth
Author: ayraphics

12. Advantages And Disadvantages Of A Static Website
Author: Manoj Singh

13. Top Dental Website Design Trends In 2025: What Your Clinic Needs To Stand Out Online
Author: PSM

14. How Can The Ecommerce Website Design Make Or Break Your Online Business?
Author: Liam Mackie

15. Best Practices To Boost Your Health & Wellness Products Selling Online
Author: Miten Shah

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: