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
Vivek NayakVivek Nayak 

Pattern attribute not working in lightning:input

Hi ,
I am using lightning:input of type text and want no special chars to be entered. Some posts say that we can use built-in pattern  attribute but its not working  for me.No idea what is missing .

<lightning:input  aura:id="BiCity"
                          label="Residential City" value=""  required="true"                                  messageWhenPatternMismatch="No special characters allowed"
                          pattern="[a-zA-Z]"
/>

Any help would be appreciated.
Thanks 
David Zhu 🔥David Zhu 🔥
Your code should work, it gives you the error if entering number or special chars.
I guess you problem is you found the value with special chars is still saved.
If that is the case, you may need to add checkValidity() method in js controller before saving.