Check if String contains URL using JavaScript

Last Reply 3 months ago By chetan

Posted 3 months ago

Client filled the form and i got the mail of filled details:

Address : Office 366, Zine Square 6, Business Bay, Https://Www.Luxuryproperty.Com/

As you can see,client used the url link in address field.

Is it Possible that we can write javascript for not accepting url link (http://,www)?

So when client enters any text like Https://Www.Luxuryproperty.Com/, the javascript message should display saying http or www links not allowed.

Any help will be appreciated.

You are viewing reply posted by: chetan 3 months ago.
Posted 3 months ago

i slightly modified your javascript and it worked:

function CheckUrl() {
    var text = document.getElementById('<%=addtxt.ClientID%>').value;
    if (new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(text)) {
        alert("Url is not allowed in address field");
        return false;
}