Both
Uri.CheckHostName(Name)
and
Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a
user has entered a valid URL?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com 8 2441
You may use this method
Public Function UriIsValid(ByVal uri As String) As Boolean
Dim ret As Boolean = False
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://", uri)
Try
Dim WebReq As HttpWebRequest = HttpWebRequest.Create(uri)
Using WebResp As HttpWebResponse = WebReq.GetResponse()
ret = True
End Using
Catch ex As Exception
Return False
End Try
Return ret
End Function
HTH
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht
news:eF**************@TK2MSFTNGP03.phx.gbl...
Both
Uri.CheckHostName(Name)
and
Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a
user has entered a valid URL?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com
might want to mention that would require an active internet or DNS server
connection to work ;)
"Michel Posseth [MCP]" <ms****@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
You may use this method
Public Function UriIsValid(ByVal uri As String) As Boolean
Dim ret As Boolean = False
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://",
uri)
Try
Dim WebReq As HttpWebRequest = HttpWebRequest.Create(uri)
Using WebResp As HttpWebResponse = WebReq.GetResponse()
ret = True
End Using
Catch ex As Exception
Return False
End Try
Return ret
End Function
HTH
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht
news:eF**************@TK2MSFTNGP03.phx.gbl...
>Both Uri.CheckHostName(Name) and Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a user has entered a valid URL?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
:-) Thank you Smokey as i am on broadband line connected it has become so
normall to me that everyone is always connected
but for the case he is not
Public Function IsvalidURI(ByVal URI As String) As Boolean
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://",
URI)
Dim RegexPattern As String =
"^((http://)|( https://))((([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*))|(([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*)))/?([a-zA-Z0-9_/?%=&+#.-~]*)$"
Dim regex As New System.Text.RegularExpressions.Regex(RegexPattern)
Return regex.IsMatch(URI)
End Function
"Smokey Grindel" <no****@nospam.comschreef in bericht
news:ue**************@TK2MSFTNGP03.phx.gbl...
might want to mention that would require an active internet or DNS server
connection to work ;)
"Michel Posseth [MCP]" <ms****@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>You may use this method
Public Function UriIsValid(ByVal uri As String) As Boolean
Dim ret As Boolean = False
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://", uri)
Try
Dim WebReq As HttpWebRequest = HttpWebRequest.Create(uri)
Using WebResp As HttpWebResponse = WebReq.GetResponse()
ret = True
End Using
Catch ex As Exception
Return False
End Try
Return ret
End Function
HTH
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht news:eF**************@TK2MSFTNGP03.phx.gbl...
>>Both Uri.CheckHostName(Name) and Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a user has entered a valid URL?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
Ah! That one is muh better.
Still I wish stuff MS gave you actually worked!
--
Anil Gupte www.keeninc.net www.icinema.com
"Michel Posseth [MCP]" <ms****@posseth.comwrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
:-) Thank you Smokey as i am on broadband line connected it has become
so normall to me that everyone is always connected
but for the case he is not
Public Function IsvalidURI(ByVal URI As String) As Boolean
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://",
URI)
Dim RegexPattern As String =
"^((http://)|(https://))((([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*))|(([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*)))/?([a-zA-Z0-9_/?%=&+#.-~]*)$"
Dim regex As New System.Text.RegularExpressions.Regex(RegexPattern)
Return regex.IsMatch(URI)
End Function
"Smokey Grindel" <no****@nospam.comschreef in bericht
news:ue**************@TK2MSFTNGP03.phx.gbl...
>might want to mention that would require an active internet or DNS server connection to work ;)
"Michel Posseth [MCP]" <ms****@posseth.comwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
>>You may use this method
Public Function UriIsValid(ByVal uri As String) As Boolean
Dim ret As Boolean = False
If uri.ToLower().StartsWith("www.") Then uri = String.Concat("http://", uri)
Try
Dim WebReq As HttpWebRequest = HttpWebRequest.Create(uri)
Using WebResp As HttpWebResponse = WebReq.GetResponse()
ret = True
End Using
Catch ex As Exception
Return False
End Try
Return ret
End Function
HTH
Michel
"Anil Gupte" <an*******@icinema.comschreef in bericht news:eF**************@TK2MSFTNGP03.phx.gbl... Both Uri.CheckHostName(Name) and Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a user has entered a valid URL?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
Anil Gupte wrote:
Ah! That one is muh better.
Still I wish stuff MS gave you actually worked!
URI's can be relative, so just testing a string directly won't tell you much.
A better test to use is the IsWellFormedUriString function, specifying an
absolute uri.
This is a little stricter than the Regex in Michel's post. If you add Michel's
test for "www", you can get a pretty good test:
If myURI.ToLower().StartsWith("www.") Then
myURI = String.Concat("http://", myURI)
End If
If Uri.IsWellFormedUriString(myURI, UriKind.Absolute) then
' now you are getting somewhere
End If
The remarks sections in MSDN describe pretty well why you are seeing the
behaviour. It also explains that CheckHostName(name) doesn't return a
boolean, but rather a UriHostNameType value.
"Anil Gupte" wrote:
Both
Uri.CheckHostName(Name)
and
Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a
user has entered a valid URL?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com
Yes, in fact I am using this fucntion:
Public Function IsValidURI(ByVal Name As String) As Boolean
Dim ValidURI As Boolean = False
If Uri.IsWellFormedUriString(Name, UriKind.RelativeOrAbsolute) Then
ValidURI = True
Else
ValidURI = False
End If
Name = Name.Replace("http://", "")
If Uri.CheckHostName(Name) Then
ValidURI = True
Else
ValidURI = False
End If
If Uri.CheckSchemeName(Name) Then
ValidURI = True
Else
ValidURI = False
End If
Return ValidURI
End Function
And only the first one works - that is URI.IsWellFormedUriString
--
Anil Gupte www.keeninc.net www.icinema.com
"Steve Gerrard" <my********@comcast.netwrote in message
news:m4******************************@comcast.com. ..
Anil Gupte wrote:
>Ah! That one is muh better.
Still I wish stuff MS gave you actually worked!
URI's can be relative, so just testing a string directly won't tell you
much.
A better test to use is the IsWellFormedUriString function, specifying an
absolute uri.
This is a little stricter than the Regex in Michel's post. If you add
Michel's test for "www", you can get a pretty good test:
If myURI.ToLower().StartsWith("www.") Then
myURI = String.Concat("http://", myURI)
End If
If Uri.IsWellFormedUriString(myURI, UriKind.Absolute) then
' now you are getting somewhere
End If
Hmm, thanx for that. I seem to remember it was a boolean return type but I
am obviously mistaken - let me try it.
Thanx again,
--
Anil Gupte www.keeninc.net www.icinema.com www.wizo.tv
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:FD**********************************@microsof t.com...
The remarks sections in MSDN describe pretty well why you are seeing the
behaviour. It also explains that CheckHostName(name) doesn't return a
boolean, but rather a UriHostNameType value.
"Anil Gupte" wrote:
>Both Uri.CheckHostName(Name) and Uri.CheckSchemeName(Name)
return true no matter what I use in "Name" (for example asdasd.sdf)
Are these actually supposed to work? Is there a better way to check if a user has entered a valid URL?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David MacQuigg |
last post by:
I'm not getting any feedback on the most important benefit in my
proposed "Ideas for Python 3" thread - the unification of methods and
functions. Perhaps it was buried among too many other less...
|
by: Steven D'Aprano |
last post by:
I've been doing a lot of reading about static methods in Python, and I'm
not exactly sure what they are useful for or why they were introduced.
Here is a typical description of them, this one...
|
by: Adrian Herscu |
last post by:
Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Thanx,
Adrian.
|
by: John Rivers |
last post by:
Hello,
What good reason there is for not allowing methods in ASPX pages I
can't imagine, but here is how to get around that limitation:
(START)
<body MS_POSITIONING="FlowLayout">
<form...
|
by: Joe Fallon |
last post by:
1. I have a Base class that has a certain amount of functionality.
2. Then I have a CodeSmith generated class that inherits from the Base class
and adds functionality.
3. Since I want to be able...
| |
by: David Hirschfield |
last post by:
Here's a strange concept that I don't really know how to implement, but
I suspect can be implemented via descriptors or metaclasses somehow:
I want a class that, when instantiated, only defines...
|
by: chandu |
last post by:
hello,
i want to know usage of static methods in a class.
is it advantageous or disadvantage to use more static methods in a class.
thank u
|
by: Cliff Williams |
last post by:
Can someone explain the pros/cons of these different ways of creating a
class?
// 1
function myclass() {
this.foo1 = function() {...}
}
// 2a
|
by: r035198x |
last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize.
These were designed to be overridden according to specific general contracts. Other classes that...
|
by: raylopez99 |
last post by:
The headline says it all. Great minds think alike: read the blog
below from three years ago, as endorsed by Ritchie, who coinvented
C.
BTW the below lambda expression code will not work (.Where...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |
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,...
|
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...
|
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...
|
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...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
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 ...
| |