473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Check if link is valid

Thew
69
I want a snippet that check if the website link is valid. For example:

www.example

returns FALSE

www.example.com

returns TRUE

www.example.co.uk

returns TRUE

www.lol.lol.lol.lol

returns FALSE

lol.example.com

returns TRUE




But how can i check that?
Sep 27 '10 #1
3 1679
Atli
5,058 Expert 4TB
There are two methods, in general, to do things like that. String manipulation and Regular Expressions. - I would be very surprised if you couldn't find a handful of examples for both via Google.

However, in the case of emails and URLs, you can use the filter_var function instead. (See the example.)
Sep 27 '10 #2
dlite922
1,584 Expert 1GB
Welcome back Thew,

With a regular expression with PHP's preg_match(). There are some you can find on google. you might need to tweak it for your use.

Regex Buddy is a tool I love to do regexps with. It also has some libraries of built-in expressions you can use.

To start you off, here's what yours might look like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ^[a-z]+\.[a-z]+\.([a-z]{3}|[a-z]{2}\.[a-z]{2})$
  3.  
  4.  
The above matches with your examples above but will fail for domains like

customer.support.company.com


Cheers,

Dan
Sep 27 '10 #3
Dormilich
8,658 Expert Mod 8TB
www.lol.lol.lol.lol

returns FALSE
why should that not be an URL? from the syntax point-of-view, this validates as URL, although the TLD (Top Level Domain) is currently invalid
Sep 27 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: nagual | last post by:
Can anyone please help me with a regular expression to test for Valid International Email Addresses? Also, which version of javascript (1.2 ?) is needed for same? Thanks. Regards.
3
by: Des | last post by:
PHP for Dummies (well that's what it's called. Page 136 "^.+@.+\.com$" this should work with eregi() Any ideas please http://www.des-otoole.co.uk/development/testmail.php Des.
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
2
by: Adrian | last post by:
Hi I have a text box where I can paste XML docs into and then send them however sometimes the call fails I assume to incorrectly formatted text! it fails on the line below: ...
3
by: satees | last post by:
Hi, I need to check the given email address is valid or not within the specified server. For eg: If i give the address xyz@yahoo.com, the code need to check with the yahoo server whether the id...
9
by: User | last post by:
Hi, Assuming the date format is in 31-Feb-2006 <head> <script language="javascript"> function t() { mill=new Date(2006, 01, 31) ;
3
by: ozzii | last post by:
I'm looking ASP code to validate certain characters that are contained in a string - for example, when a user enters a username or password, I want to limit the characters to a..z, A..Z,0..9, _, -,...
4
by: Anthony2oo5 | last post by:
Hey there, I'm trying to write a script for uploading images but only with certain file extensions. Currently I have it working by: if (($FileExt = "jpg") || ($FileExt = "gif")) ect, but is...
2
by: lucky13 | last post by:
Hello All, I want to check the Valid E-mail id is entered by user or not in the e-mail id field. means if user will not enter the @ sign & Domain name , user must receive a message that" Please...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.