HTML5 > Forms Elements

Validate url in HTML5

How to validate if entered text is a valid url in the text box in HTML5?


To detect whether the entered text is a valid url in the Text box, we can set the type attribute to “url”.

<body>
    <form>
       Url: <input type="url" id="myUrl" required name="myUrl" />
    </form>
</body>

Output

Unless url starts with http* (followed by any other characters), the textbox is marked as invalid and error message is displayed.

 Views: 4508 | Post Order: 92



Write for us






Hosting Recommendations