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
Himanshu KambleHimanshu Kamble 

i want to restrict user to enter special characters into the Lightning-textarea how we can possible this thing. In lightening input we have a pattern attributes but in textarea we dont have any so pls give me approch regarging that

User-added image
Vinay MVinay M

Hi Himanshu,

You can utilize "onchange" event on lightning-textarea fields and call a method in JS to validate the input. For instance :
 
 

HTML:

<lightning-textarea name="input2" 
label="Textarea field with a predefined value"
value="initial value"
onchange={handleChange}
data-field="textArea1"
>
</lightning-textarea>

JS :

handleChange() {
let textAreaField = this.template.querySelector('[data-field = "textArea1"]');
if (textAreaField.value.match('[\\p{L}\\s\\d]*$')) {
      textAreaField.setCustomValidity('Invalid entry');
    } else {
      textAreaField.setCustomValidity('');
    }
    return textAreaField.reportValidity();
}

Please mark it as best answer if this solves your issue. 

Thank you,

Vinay.