Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello,
I want web site url validation using javascript acn u send any snippets or guide lines
Posted
Updated 30-Apr-12 20:26pm
v2
Comments
Rahul Rajat Singh 1-May-12 2:28am    
What do want to validate? please elaborate.
kingsa 1-May-12 2:30am    
website address

Hi ,
you can use regularexpression
ASP.NET
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
    ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Error"
    ForeColor="#FF3300" SetFocusOnError="True"
    ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?"
    ValidationGroup="yourgroup"></asp:RegularExpressionValidator>

Best Regards
M.Mitwalli
 
Share this answer
 
JavaScript
var s = window.location.host
if(s.indexOf("www.mywebsite.com") == -1)
{
      //the url is not mine so do what need to be done.
}
 
Share this answer
 
Please check below code

function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}


Hope it will help
 
Share this answer
 
Please check this out...!


JavaScript
function is_valid_url(url)
{
     return url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900