C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Validating a URL(simple!!!!!!!!!!)


Posted Date: 12 Aug 2008    Resource Type: Code Snippets    Category: Validations

Posted By: Bharani Peddakotla       Member Level: Silver
Rating:     Points: 10



I have written the following code to validate a url.


function validarURL(strfieldId)
{
var arrURL=document.getElementById(strfieldId).value.split('.');
var returnval=true;
if(arrURL.length<3)
{
alert('Please enter valid url.');
document.getElementById(strfieldId).value='';
document.getElementById(strfieldId).focus();
returnval=false;
}
else
{
for(var j=0;j {
if(arrURL[j]=='')
{
alert('Please enter valid url.');
document.getElementById(strfieldId).value='';
document.getElementById(strfieldId).focus();
returnval=false;
}
}
if(!(arrURL[0]=='www'))
{
alert('Please enter valid url starting with www.');
document.getElementById(strfieldId).value='';
document.getElementById(strfieldId).focus();
returnval=false;
}
}
return returnval;

}


Here strfieldId refers to the ControlId containing the URL.




Responses

Author: Deepak S    14 Aug 2008Member Level: Gold   Points : 2
You can also use dis to validate url:
function isValidURL(url){
var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if(RegExp.test(url)){
return true;
}else{
return false;
}
}

if(document.getElementById("txtWebsite").value!="")
{
//Check if the url has the correct format
if(isValidURL(document.getElementById("txtWebsite").value)!=true)
{
document.getElementById("lblError").innerHTML="Please Enter Valid Website Address";
document.getElementById("txtWebsite").focus();
return false;
}
}


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Website format  .  Validating URL  .  Validate URL  .  Validate  .  URL validating  .  URL  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Remove Trailing and Extra Spaces/Non-Printing Characters
Previous Resource: Validating Guid
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it outsourcing

Contact Us    Privacy Policy    Terms Of Use