Web Url validation

There is a small error in the code | I’ll fix it soon. If you know it, let me know as well

<?php //php protion ?>

<?php

// Firstly I have defined the variables here and set them to empty values
$websiteErr = ""; 

if(isset($_post["btn"])){
     $web = $_post["site"];

    if (!preg_match("/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i",$web)) {
      $websiteErr = "Invalid URL";
    }

    }

?>

<?php //html portion ?>

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple html form by TALHA SHOAIB</title>
</head>
<body>

<h3>Web Url validation | code avaialble at <a href="https://techkwave.blogspot.com/">Tech wave</a></h3>

     
        <form action="" method="post">
         
            <label>Website Url:</label>
            <input type="text" name="site">
            <span style="color: red;">*<?php echo $websiteErr; ?></span>
            <br>
            <input type="submit" name="btn" value="Button">
        </form>
</body>
</html>

Share it in your network:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

small_c_popup.png

Congratulations!

You have successfully subscribed to my email list. Now you will be recieving latest wordpress tips and tricks directly in your mail box.

Don’t worry! I won’t spam you