I have a field that checks for 2 patterns. What I currently have is, in the text field's onchange handler, i check if the inputted string matches a certain pattern. However, I want to use lightning's OOTB feature that colors the field red and shows a label below the field if a pattern is invalid. I can do just that for 1 pattern:

<lightning:input aura:id="myField" label="test field" value="{!v.valHolder}" onchange="{!c.txt_change_testHandler}" pattern="\d{8}" />

The above snippet works. As you can see, it's just a simple pattern. But I currently have 2 patterns to check. The 2nd pattern looks something like this:


My problem now is, how do I check for these 2 patterns via the lightning input's pattern attribute, and not use the onchange handler at all?


Use the "OR" operator (|):


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.