Wednesday, May 29, 2013

Website URL validation in Java Script

funtion WebsiteValidation(){
 var website = document.getElementById("<%=TxtWeb.ClientID %>").value.toLowerCase();
            if (website != "") {
                var websitePart = website.split(".");
                    if (websitePart.length > 2) {
                    if (websitePart[0] == "www" && websitePart[1].length > 1 && websitePart[websitePart.length - 1].length < 4 && websitePart[websitePart.length - 1].length > 1) {
                    }
                    else {
                        alert('Invalid website');
                        return false;
                    }
                }
                else {
                    alert('Invalid website');
                    return false;
                }
            }
}