I want to make https or http optional in my url type input field. But I always get invalid format error. I've tried regex pattern as well, but no luck.

HTML Code:

<lightning-input type="url" value={value} class="slds-p-horizontal--xx-small" variant="label-hidden"  pattern="((ftp|http|https):\/\/)?" name="input1" onblur={updateValue} onchange={updateValue} disabled={isdisabled}></lightning-input>

JS Code:

updateValue(event) {
   this.value = event.target.value;

1 Answer 1


The "url" type has its own validations, and you can't bypass these. If you want a freeform text where the user doesn't need to put in a complete URL, use "text" instead, and you can use a pattern to specify exactly what you expect as a regular expression.

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.