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

Sting to Bits conversion

Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #1
10 1432
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #2
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #3
Then find a Regular expression match string for IP Addresses and plug it in.
There are many good examples, all you need to do is google or MSN Search
"Regex" "IP address".

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Hello, everyone.
>
I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?
>
Thanks,
>
Antonio
Aug 6 '06 #4
Thank you for the suggestion.
"Peter Bromberg [C# MVP]" wrote:
Then find a Regular expression match string for IP Addresses and plug it in.
There are many good examples, all you need to do is google or MSN Search
"Regex" "IP address".

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Antonio" wrote:
>
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #5
Why using newsgroups and ask questions to experts, when you can "google" it?

"Peter Bromberg [C# MVP]" wrote:
Then find a Regular expression match string for IP Addresses and plug it in.
There are many good examples, all you need to do is google or MSN Search
"Regex" "IP address".

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Antonio" wrote:
>
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #6
Antonio,
That's certainly a valid question. Let me try to answer it with a 4,000 year
old quote from Confucius:
"Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed him for a lifetime"

Cheers,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Why using newsgroups and ask questions to experts, when you can "google" it?

"Peter Bromberg [C# MVP]" wrote:
Then find a Regular expression match string for IP Addresses and plug it in.
There are many good examples, all you need to do is google or MSN Search
"Regex" "IP address".

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....
>
Antonio
>
"Peter Bromberg [C# MVP]" wrote:
>
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"Antonio" wrote:

Hello, everyone.
>
I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?
>
Thanks,
>
Antonio
Aug 6 '06 #7
and the 2006 answer is: How can you teach a man to fish, if he doesn't know
how to progressivly setup the fishing equipment? What comes first.

Your answer to direct me to pages that don't even mention IP addresses or
bytes conversion, and it doesn't give me an example, doesn't really help me
understand the logic behind these controls and what I can do with them.

As you can convert string to integer, you don't need a plug-in, but
understand how to format the code to convert string to byte, which is a
feature in VS.

"Peter Bromberg [C# MVP]" wrote:
Antonio,
That's certainly a valid question. Let me try to answer it with a 4,000 year
old quote from Confucius:
"Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed him for a lifetime"

Cheers,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Why using newsgroups and ask questions to experts, when you can "google" it?

"Peter Bromberg [C# MVP]" wrote:
Then find a Regular expression match string for IP Addresses and plug it in.
There are many good examples, all you need to do is google or MSN Search
"Regex" "IP address".
>
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Antonio" wrote:
>
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:

Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Antonio" wrote:
>
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio
Aug 6 '06 #8
KH
Regex is a little overkill for what you're doing; how about:

bool IsValidIP(string input)
{
string[] split = input.Split('.');
int i = 0;
byte b;

if (split.Length == 4)
{
for (; i < split.Length; ++i)
{
if (!Byte.TryParse(split[i], out b))
{
break;
}
}
}

return (i == 4);
}
"Antonio" wrote:
The IP address is not an option on the RegularExpression Validator control.
E-Mail and URL are the only computer-related options. The rest are phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:
Just use a RegularExpression Validator on the field and set it to the IP
address option.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Hello, everyone.
>
I have textboxes in which users enter IP Addresses. I would like to check
what they entered when they press the Submit button to make sure that they
entered an IP that's between 0 and 255 and display an error message if they
entered any number >255. Can someone give me an example?
>
Thanks,
>
Antonio
Aug 6 '06 #9
Can you declear a byte from the beginning like:

private void button1_Click(object sender, EventArgs e)
{
byte bteIP;
if (IsNumeric(textBox1.Text))
{
bteIP = System.Convert.ToByte(textBox1.Text);
if ((bteIP >= 0) && (bteIP <= 255))
{
//Put your on error message
}
}
}

Validator is web control and not winform control. So if you are doing
Winform app then forget about it.

chanmm
"Antonio" <An*****@discussions.microsoft.comwrote in message
news:B7**********************************@microsof t.com...
and the 2006 answer is: How can you teach a man to fish, if he doesn't
know
how to progressivly setup the fishing equipment? What comes first.

Your answer to direct me to pages that don't even mention IP addresses or
bytes conversion, and it doesn't give me an example, doesn't really help
me
understand the logic behind these controls and what I can do with them.

As you can convert string to integer, you don't need a plug-in, but
understand how to format the code to convert string to byte, which is a
feature in VS.

"Peter Bromberg [C# MVP]" wrote:
>Antonio,
That's certainly a valid question. Let me try to answer it with a 4,000
year
old quote from Confucius:
"Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed him for a lifetime"

Cheers,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:
Why using newsgroups and ask questions to experts, when you can
"google" it?

"Peter Bromberg [C# MVP]" wrote:

Then find a Regular expression match string for IP Addresses and plug
it in.
There are many good examples, all you need to do is google or MSN
Search
"Regex" "IP address".

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Antonio" wrote:

The IP address is not an option on the RegularExpression Validator
control.
E-Mail and URL are the only computer-related options. The rest are
phone
numbers, postal codes, zip code, SS#....

Antonio

"Peter Bromberg [C# MVP]" wrote:

Just use a RegularExpression Validator on the field and set it to
the IP
address option.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Antonio" wrote:
>
Hello, everyone.

I have textboxes in which users enter IP Addresses. I would
like to check
what they entered when they press the Submit button to make
sure that they
entered an IP that's between 0 and 255 and display an error
message if they
entered any number >255. Can someone give me an example?

Thanks,

Antonio

Aug 6 '06 #10
KH wrote:
Regex is a little overkill for what you're doing; how about:

bool IsValidIP(string input)
In Framework 2.0 there IPAddress.TryParse already implemented for us!
Earlier we can use IPAddress.Parse and catch any FormatException.

--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 7 '06 #11

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

Similar topics

19
by: cppaddict | last post by:
Hi, I am going to have a series of bit flags which I could store in an array, or as a string ("10011001"), or any other way. I want to be able to turn this series of bits into an int. I know...
14
by: Ben | last post by:
Hi, I need to write some data types into an array of unsigned chars. These are basically "signals" within a message, so each signal will have a start bit and a length. The signals will also...
26
by: G Patel | last post by:
Hi, I'm wondering if anyone knows if the following function will function properly as a set-bit counter on non 2s complement machines (as K&R2 implies). | int bitcount(unsigned x) | { | ...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
15
by: Sync_net | last post by:
I am not sure if this a valid topic to be asked in the groups. --Kindly suggest me a technique/algorithm by which i can convert a stream of data (we could take it to be characters -- stream of 8...
4
by: Alan Ning | last post by:
Hi all, Say I have the following, string str("Hello World\n") I would like to extract 5 bits at a time from the string. I am doing this to convert ascii string to another string type. Is...
82
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure...
77
by: borophyll | last post by:
As I read it, C99 states that a byte is an: "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment" (3.6) and that a byte...
8
by: myfem.analyzer | last post by:
Hi, I saw a line of codes in the "Fast Inverse Square Root" like this: Float InvSqrt(float x) { ....... int i = *(int *) &x; //get bits for floating value ..... x = * (float *) &i; ...
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:
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...
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,...
0
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...

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.