473,856 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7828
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.Re gularExpression s.Regex.IsMatch ("W1A 1BC",postCodeRe gEx) ==
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*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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*********@ya hoo.co.uk> wrote in message
news:uu******** ******@TK2MSFTN GP09.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.Re gularExpression s.Regex.IsMatch ("W1A 1BC",postCodeRe gEx)
== 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*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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*********@ho tmail.com> wrote in message
news:Od******** ******@TK2MSFTN GP15.phx.gbl...
Oh! it's too dificalt for me can you show me it for IP validating please?

"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:uu******** ******@TK2MSFTN GP09.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.Re gularExpression s.Regex.IsMatch ("W1A 1BC",postCodeRe gEx)
== 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*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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.co m
"Dave" <da*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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
4595
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) from Microfost MSDN Library for my project "validateXML". When I did "Build" on my project, I got the following fatal error C1010: c:\Documents and Settings\SHC\My Documents\Visual Studio Projects\valoidateDOM\valoidateDOM.cpp(273): fatal error...
5
2531
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 invoked. I am probably wrong about that. If I am suppose to use this function, the edits seemed to be invoked even when you have pressed the cancel and the "CausesValidation" is set to false. Is there a way to get around this (might just be an...
11
11775
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
0
2656
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 XML document? I was hoping to use the XmlDocument.Validate(ValidationEventHandler, XmlNode) method for that - doesn't seem to work...
4
2608
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
24
2122
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 automate and clean up parameter validation code. It's almost ready to go into open beta. But one last little glitch is holding me up, and that would be the name of the factory class that serves as the entry point into the library: Validate.
0
9922
marktang
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...
0
11066
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, 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...
0
10702
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9536
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, 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...
1
7935
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7099
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5963
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4177
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
bsmnconsultancy
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...

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.