function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hari Sankar R 9Hari Sankar R 9 

custom validation in LWC

Hi,
I JUST WANT SOME SMALL MODIFICATIONs,,,AND ADD SOME VALIDATIONS

Like in Name if i will give null input it will throw the error “INVALID NAME”. Like phone number  if i will give null input it will throw the error “INVALID phone"
Best Answer chosen by Hari Sankar R 9
Oshin AgrawalOshin Agrawal
Hi,

You will need to use setCustomValidity() and reportValidity() methods to validate and display custom errors.Refer to the below documentation: 

https://developer.salesforce.com/docs/component-library/bundle/lightning-input/documentation
Please mark this resolved by using best answer if this solves your issue.

Thank you

All Answers

Hari Sankar R 9Hari Sankar R 9
Hi,
I JUST WANT SOME SMALL MODIFICATIONs,,,AND ADD SOME VALIDATIONS

Like in Name if i will give null input it will throw the error “INVALID NAME”. Like phone number  if i will give null input it will throw the error “INVALID phone"   with the alert message I need to populate.
Oshin AgrawalOshin Agrawal
Hi,

You will need to use setCustomValidity() and reportValidity() methods to validate and display custom errors.Refer to the below documentation: 

https://developer.salesforce.com/docs/component-library/bundle/lightning-input/documentation
Please mark this resolved by using best answer if this solves your issue.

Thank you
This was selected as the best answer
Hari Sankar R 9Hari Sankar R 9
Hi,

Record edit page in lightning input field like name & phone number  validation ,ADD SOME VALIDATIONS using LWC

Please help me out