javascript - how to create patterns in TextBox? -
notes : tired questions & answer related topic. this
i use simple form use url textbox use patterns pattern="https?://.+" perfect work.
i want 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: using pattern try solve problem. not other script
my code here
you may use alternation this:
pattern="(www\.|https?://).+" ^ ^ ^ a case-insensitive version:
pattern="([ww][ww][ww]\.|[hh][tt][tt][pp][ss]?://).+" see regex demo. note case insensitive version can shortened of limiting quantifiers: pattern="([ww]{3}\.|[hh][tt]{2}[pp][ss]?://).+".
it accept input starting 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>
Comments
Post a Comment