What kind of regular expression pattern is needed to check
if URL is valid? It's enought if most of cases are covered.
I have PHP 4.x.
Br 8 2766
John V wrote: What kind of regular expression pattern is needed to check if URL is valid? It's enought if most of cases are covered.
I have PHP 4.x.
Br
Personally, I check if the last part of the domain name (the .com, .net,
..info) part is greater than one character (to allow for country specific
domain names like ca or uk) and less than 8 characters (because I
believe there are also .museum or similar available on the net, andmore
will eventually follow).
I should (but don't) check if the last part of the domain name is
numeric (thus instead of .com that the user had entered .co1 or something).
I do check that there are at least three 'portions' to the domain name -
thus http://www.com would fail but www.xyz.com would pass - Or xyz.co.uk
would also pass...
And what about the protocol? Are you only refering to web http://
style addresses? If true, then check for that too... I believe there is
a maximum length for a domain name but I don't know what that is - I
have a self imposed limit of 64characters.
Lastly - your url should I believe only contain alphanumeric input, in
addition to _ (underscore) characters (though I believe you could also
have a dash, but I think this is not recommended).
Does that help you any?
randelld
Randell D. <re************ *************** ***@fiprojects. moc> wrote: What kind of regular expression pattern is needed to check if URL is valid? It's enought if most of cases are covered.
You can't check it this way. Why not check if it actually exists?
Personally, I check if the last part of the domain name (the .com, .net, .info) part is greater than one character (to allow for country specific domain names like ca or uk) and less than 8 characters (because I believe there are also .museum or similar available on the net, andmore will eventually follow).
fo*@bar.invalid is a valid URL accoring to RFC 2606 but email will never
be delivered to it.
I do check that there are at least three 'portions' to the domain name - thus http://www.com would fail but www.xyz.com would pass - Or xyz.co.uk would also pass...
Funny example:
lynx -head -dump http://www.com/
HTTP/1.0 200 OK
Server: Resin/2.1.14
ETag: "AAAAQH7CT4 Q"
Last-Modified: Thu, 10 Feb 2005 06:51:22 GMT
Content-Type: text/html
Content-Length: 9538
Date: Sun, 20 Feb 2005 03:23:06 GMT
A valid URL it seems
And what about the protocol? Are you only refering to web http:// style addresses? If true, then check for that too... I believe there is a maximum length for a domain name but I don't know what that is - I have a self imposed limit of 64characters.
Lastly - your url should I believe only contain alphanumeric input, in addition to _ (underscore) characters (though I believe you could also have a dash, but I think this is not recommended).
Heard of IDN?
So while above test might be a good start (and be better than no checks)
the best test is to actually check if the URL is valid. Even better
would be a kind of challenge/response test (a must for email URLs).
On Sun, 20 Feb 2005 00:56:31 GMT, "Randell D."
<re************ *************** ***@fiprojects. moc> wrote: I do check that there are at least three 'portions' to the domain name - thus http://www.com would fail but www.xyz.com would pass - Or xyz.co.uk would also pass... http://xyz.com is a valid URL.
--
Regards, Paul Herber, Sandrila Ltd. http://www.pherber.com/
SanDriLa - SDL/MSC/TTCN/UML2 application for Visio http://www.sandrila.co.uk/
email address is spam-trapped - s/*@/paul@/
Daniel Tryba wrote: fo*@bar.invalid is a valid URL accoring to RFC 2606 but email will never be delivered to it.
Funny - I was under the impression that email is never delivered to
URLs :)
--
Markku Uttula
Randell D. wrote: Personally, I check if the last part of the domain name (the .com, .net, .info) part is greater than one character (to allow for country specific domain names like ca or uk) and less than 8 characters (because I believe there are also .museum or similar available on the net, andmore will eventually follow).
And thus you negate the possibility of passing in numeric URLs. Never
heard of IP names?
I do check that there are at least three 'portions' to the domain name - thus http://www.com would fail but www.xyz.com would pass - Or xyz.co.uk would also pass...
Why? As has been pointed out, www.com exists and is fully valid URL.
There are others too.
And what about the protocol? Are you only refering to web http:// style addresses? If true, then check for that too... I believe there is a maximum length for a domain name but I don't know what that is - I have a self imposed limit of 64characters.
What matter does that have? The question was about URL, and in that
domain name length plays a very little part.
Lastly - your url should I believe only contain alphanumeric input, in addition to _ (underscore) characters (though I believe you could also have a dash, but I think this is not recommended).
In addition, there can be a lot more characters, because we're talking
about a URL, not "domain name part" of URL.
--
Markku Uttula
John V wrote: What kind of regular expression pattern is needed to check if URL is valid? It's enought if most of cases are covered.
I wouldn't recommend using regular expression to do that. Why do it
the hard way :)
A much better solution is to attempt to connect to the given domain,
and if that is possible, request (for example) HEAD-command with the
URL entered. This would (of course) only check if the connection to
the given URL is possible at the given time from the machine you're
running the script from, but this is always the case with WWW :)
--
Markku Uttula
Markku Uttula <ma***********@ disconova.com> wrote: fo*@bar.invalid is a valid URL accoring to RFC 2606 but email will never be delivered to it.
Funny - I was under the impression that email is never delivered to URLs :)
A common mistake, worth reading:
mailto URL scheme: http://www.ietf.org/rfc/rfc2368.txt
Generic URI syntax: http://www.ietf.org/rfc/rfc2396.txt
But I see I forgot the scheme from my example url :)
Randell D. wrote: John V wrote:
[snip] It's enought if most of cases are covered.
[snip]
I never said my solution covered everything - nor did the OP request
this... but I do think my suggestion covered most cases...
Thanks for pointing out things I hadn't thought off though,
randelld This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: - ions |
last post by:
I have created a JComboBox with its Items as a list of "M" numbers ie.
M1,M2,M3.......throgh too M110 (thes are the messier objects, a
catolouge of deep sky objects) the user selects of of these and views
it aswell as infomation. The program also has a JTextFiels which
allows the user to enter the M number. The problem i have is checking
that what the user has entered is valid, that being an M followed by 1
- 110 Nothing else, i thought of...
|
by: William Payne |
last post by:
Hello, I am in the process of converting a C++ program to a C program. The
user of the program is supposed to supply an integer on the command line and
in the C++ version of the program I was using something called stringstreams
to do the conversion. Here's my C version, can I leave it as it is or does
it need to be robustified or changed in any manner, regarding error
checking?
char* endptr;
errno = 0;
|
by: Mikhail Teterin |
last post by:
Hello!
Consider the following simple accessor function:
typedef struct {
int i;
char name;
} MY_TYPE;
const char *
|
by: Marlene Stebbins |
last post by:
I am entering numbers into my program from the command line. I want to
check whether they are > INT_MAX. Sounds simple, but I've discovered that
if(x <= INT_MAX)
{
/* use x in some calculation */
}
else
{
/* exit with error message */
|
by: JD |
last post by:
Within asp.net I know it is possible to validate that a user has entered
in a correctly formatted email address. However, what I want to be able
to do is to verify that the email address entered is actually going to
work. As in that it will receive email.
I have been looking at one way to do this, and that is to see if the
domain part of the email address is a valid domain, but I was wondering
if there was a better way of checking to see...
| |
by: Fredrik Tolf |
last post by:
If I have a variable which points to a function, can I check if certain
argument list matches what the function wants before or when calling it?
Currently, I'm trying to catch a TypeError when calling the function
(since that is what is raised when trying to call it with an illegal
list), but that has the rather undesirable side effect of also catching
any TypeErrors raised inside the function. Is there a way to avoid that?
Fredrik Tolf
|
by: atv |
last post by:
Hi,
Just to check, if i set a pointer explicitly to NULL, i'm not allowed
to dereference it? Why is that, it's not
like it's pointing to any garbage right? Why else set it to NULL. I can
remember some instances where
i did just that and printf reported something like : (null).
I'm asking because i read somewhere that it is not valid. I thought it
simply wasn't valid to dereference
a pointer who is _not_ set to point to anything.
|
by: xhe |
last post by:
Hi,
I need to program to check the validity of IP address through PHP
Initially I used this one:
$url="http://www.ntc.gov.au/ViewPage.aspx?
page=A02400304500100020";
$fp=fopen($url,"r");
if(!$fp)
{
|
by: jacob navia |
last post by:
We hear very often in this discussion group that
bounds checking, or safety tests are too expensive
to be used in C.
Several researchers of UCSD have published an interesting
paper about this problem.
http://www.jilp.org/vol9/v9paper10.pdf
Specifically, they measured the overhead of a bounds
|
by: geetamadhavi |
last post by:
Hi All,
I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i even tried with echo also how to solve this the message should come under in the same window only see my code it is
program
----
<?php
// Connects to your Database
mysql_connect('localhost', 'root', 'epara') or die(mysql_error());
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |