1

Notes : i tired all questions & answer related this topic. Like This

I use simple Form Use URL TextBox i use patterns pattern="https?://.+" that perfect work.

I want to allow Text (small & uppercase) Like

1. www.test.com
2. https://www.test.com
3. https://test.com
4. WWW.TEST.COM
5. HTTPS://WWW.TEST.COM*
6. HTTP://TEST.COM

i tried Code :

<input name="website" id="website" type="text" class="Custom_textbox"  pattern="https?://.+"/>

Notes: Only Using pattern try to solve my problem. not other script

My code Here

Community
  • 1
  • 1
Sumit patel
  • 3,807
  • 9
  • 34
  • 61

1 Answers1

1

You may use an alternation like this:

pattern="(www\.|https?://).+"
         ^     ^         ^

A case-insensitive version:

pattern="([wW][wW][wW]\.|[hH][tT][tT][Pp][sS]?://).+"

See the regex demo. Note that the case insensitive version can be shortened with the help of limiting quantifiers: pattern="([wW]{3}\.|[hH][tT]{2}[Pp][sS]?://).+".

It will accept any input starting with www. or http:// or https://.

input:valid {
  color: black;
}
input:invalid {
  color: red;
}
<form name="form1"> 
  <input name="website" id="website" type="text" class="Custom_textbox"
     pattern="([wW][wW][wW]\.|[hH][tT][tT][Pp][sS]?://).+" 
     title="Please valid url" required/>
  <input type="Submit"/> 
</form>
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563