REGEX patterns in LWC
How to use pattern attribute in LWC lightning-input base component for data validation.
Let's see how this works with an example:
Get the correct REGEX pattern for validation: Consider a scenario where you want users to submit valid email address. You can learn, generate and validate your own expression as needed with tools like: https://regex101.com/
Apply the REGEX pattern to the lightning-input component instance using 'pattern' attribute.
Specify a message to be shown to users for if the data entered doesn't match the specified pattern using the 'message-when-pattern-mismatch' attribute.
Here is how our Email validation lightning-input field should look like (Note: The pattern can be generated as per specific business needs, below is a simple email validation pattern):