Skip to content

Instantly share code, notes, and snippets.

@sfmishra
Last active December 3, 2019 21:48
Show Gist options
  • Save sfmishra/11209e7ec9565c9b330d440fa6ee7524 to your computer and use it in GitHub Desktop.
Save sfmishra/11209e7ec9565c9b330d440fa6ee7524 to your computer and use it in GitHub Desktop.
import { LightningElement } from 'lwc';
export default class lwcInput extends LightningElement {
handleChange(event) {
let inputCompValue = event.target.value;
let inputComp = this.template.querySelector('.inputComp');
let splChars = /[0-9(@!#\$%\^\&*\)\(+=._-]/;
if(inputCompValue.match(splChars)) {
inputComp.setCustomValidity("Only character allowed.");
inputComp.reportValidity();
} else {
inputComp.setCustomValidity('');
inputComp.reportValidity();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment