vendredi 9 décembre 2016

Input box using a regex pattern not working with form?

I was working on a project that required a regex pattern. I wrote the code, but then I simply changed the <form action=""> to a different page which I then put the code on. For some reason, the regex pattern on the input box is not working.

Here is my code:

<html>

<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>

<body>
        <form method="GET" action="/sucess.php">
            <input name="host" type="text" placeholder="type a host! eg. 127.0.0.1 or example.com" pattern="((([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$)+[/]|(?:http:\/\/|www\.|https:\/\/)([^\/]+)|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" style="width: 300px;" title="Enter a valid host that fits the format of a domain or IPv4 Address" required>
            <button type="submit" id="submitDemo">fire da lazar</button>
        </form>

</body>

</html>

As you can see, I have set a pattern on the HTML input box, but it's not working when I run it. When I enter some text on my website, it just submits the form and goes to the sucess.php page before checking if the input matches the pattern.

Could someone please help me get the pattern working? If you need the sucess.php code, just ask!

Aucun commentaire:

Enregistrer un commentaire