1

I am writing directly in internamform.js code. I don't have any HTML code. I am getting error first time when i select the field standard error "Your Entry does not Match the allowed Pattern"

this.objMap.textvalue__c.maxlength="10";
if((this.objMap.textvalue__c.length!=10)

 { 
    console.log('test')
    this.allValid = false;
    let textid=this.objMap.textvalue__c
    textid.pattern=".{10}"
    textid.errMsg = "Enter 10 characters"
}

Only first I am getting this statndard error, for the second time the error is showing correctly "Enter 10 characters" How to overcome this error.

How to overcome the standard error "Your Entry does not match the allowed pattern"

1 Answer 1

0

Don't check for specific conditions, simply use the reportValidity and checkValidity methods. I wrote a demo for you to show how you can validate your inputs.

  validate() {
    let fields = [...this.template.querySelectorAll('lightning-input')]
    let validities = fields.map(field => {
      field.reportValidity()
      return field.checkValidity()
    })
  this.allValid = validities.every(valid => valid)
}

<lightning-input label="Demo 1" pattern="^.{10}$" required
    message-when-pattern-mismatch="Please enter 10 characters exactly">
</lightning-input>
<lightning-input label="Demo 2" pattern="^.{10}$" required
    message-when-pattern-mismatch="Please enter 10 characters exactly">
</lightning-input>
<lightning-input label="Demo 3" pattern="^.{10}$" required
    message-when-pattern-mismatch="Please enter 10 characters exactly">
</lightning-input>
<lightning-input label="Demo 4" pattern="^.{10}$" required
    message-when-pattern-mismatch="Please enter 10 characters exactly">
</lightning-input>
<lightning-button onclick={validate} label="Validate">
</lightning-button>
1
  • thank you so Much for the answer, I dont have Html , is it possible to write without html? Commented Feb 8, 2022 at 1:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .