473,404 Members | 2,187 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,404 software developers and data experts.

Validate IP

Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.
Nov 16 '05 #1
5 7799
you need to use regular expressions.

i.e. to validate a uk post code example

string postCodeRegEx =
@"(^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$)|(^
*$)";

if (System.Text.RegularExpressions.Regex.IsMatch("W1A 1BC",postCodeRegEx) ==
false) {
MessageBox.Show("Not a valid post code");
}

Regular expressions look fairly daunting, but like a complex SQL query, if
you do it in parts, they're fairly straight forward.

You need to know about www.regexlib.com also, otherwise you'll spend ages
reinventing the wheel. Here you can find literally 1,000s of reg
expressions people have already written.
There are also tools for testing them, etc.

HTH
Sam
"Dave" <da*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.

Nov 16 '05 #2
Hi Dave,

You can use regular expressions. Here's how:

http://msdn.microsoft.com/library/de...xpressions.asp

And here's a site you can search for regular expressions without having to
create all of them yourself:

http://regexlib.com/

Joe
--
http://www.csharp-station.com

"Dave" <da*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.

Nov 16 '05 #3
Oh! it's too dificalt for me can you show me it for IP validating please?

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
you need to use regular expressions.

i.e. to validate a uk post code example

string postCodeRegEx =
@"(^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$)|(^
*$)";

if (System.Text.RegularExpressions.Regex.IsMatch("W1A 1BC",postCodeRegEx)
== false) {
MessageBox.Show("Not a valid post code");
}

Regular expressions look fairly daunting, but like a complex SQL query, if
you do it in parts, they're fairly straight forward.

You need to know about www.regexlib.com also, otherwise you'll spend ages
reinventing the wheel. Here you can find literally 1,000s of reg
expressions people have already written.
There are also tools for testing them, etc.

HTH
Sam
"Dave" <da*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.


Nov 16 '05 #4
you're having a laugh right, all you had to do was get another regular
expression from the site listed in both responses to your post

one Reg ex i got from that very site after search for "IP" was
@"\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b"(try
it, http://www.regexlib.com/Search.aspx >> "IP" >> Search)

If you send me you prject specification, i'll code it all for you

HTH
Sam

(ps, im only joking)
"Dave" <da*********@hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP15.phx.gbl...
Oh! it's too dificalt for me can you show me it for IP validating please?

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
you need to use regular expressions.

i.e. to validate a uk post code example

string postCodeRegEx =
@"(^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$)|(^
*$)";

if (System.Text.RegularExpressions.Regex.IsMatch("W1A 1BC",postCodeRegEx)
== false) {
MessageBox.Show("Not a valid post code");
}

Regular expressions look fairly daunting, but like a complex SQL query,
if you do it in parts, they're fairly straight forward.

You need to know about www.regexlib.com also, otherwise you'll spend ages
reinventing the wheel. Here you can find literally 1,000s of reg
expressions people have already written.
There are also tools for testing them, etc.

HTH
Sam
"Dave" <da*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.



Nov 16 '05 #5
Dave,

To validate an IP address, use the static Parse method on the IPAddress
class in the System.Net namespace.

To validate the email address in a string, I would use the Uri class,
adding "mailto:" before the address, and trying to create a Uri instance
from that. If it throws an exception, then you know it is not valid.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <da*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello.

Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.

Thank you.

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
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,...
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
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...
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.