1

I have created a small form which have one field for input the url and the other one is submit button and i want to validate the input url through the javascript so that in case of correct url it will show an alert box.Is it possible with javascript? If yes , please help me to getting this through the below code.

<form name="lln-form" class="llnfrm" id="lln-form" id="bulk-form" action="" method="post" onsubmit="javascript:event.preventDefault();return  submit_ajax();">
<fieldset style="">
<label>Enter URL:</label>
<input type="text" name="url" placeholder = "enter your url">
</fieldset>
<input class="lln-button button button-primary" type="submit" name="lln-submit" id="llnbuton" value="Save" onsubmit = "saveURL()"; />
</form>
<script type="text/javascript">
function saveURL()
{
<?php
        if(isset($POST['url'])==true&&empty($POST['url'])==false){
$url=$POST['url'];
if(filter_var('$url',FILTER_VALIDATE_URL)==true)
    echo "VAlid URL";
}
    ?>
}

5

1 Answer 1

2

You can try

var txturl=document.getElementById('TXTURL');
valid=txturl.value.search(/^([\w-]+(?:\.[\w-]+)*).((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2,4})?)$/i );
if(valid!=0){
    alert("Invalid URL");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.