Custom validation in Lightning web component

297 Views

As Lightning component is kinda new and I was struggling finding ways to add custom validation on any field (lightning-input specially) and even very little information is available all over internet (yet) and I assume others may be struggling for the same solution. Luckily, it worked out for me and I am sharing the JS method which will add custom error validation on any field.

In this method, I am getting the date value and checking if its empty then print some error on field and returning back the null value else remove the error message (if any) and return the entered value.

Happy Coding !

Leave a Comment