Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
    Bookmark Topic Watch Topic
  • New Topic

IP Address format

 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have to check for the valid IP Address that is being entered by the user before the IP Address is used for querying the database.

Here are the rules:

if someone enters leading zeroes, for example 192.051 or 192.051.088 the leading zero would be stripped ip address used will be 192.51 or 192.51.88

and

IP Address should have periods at right places


like 192.27.88.128
192.27.88
192.27
192

are all valid entries where as

192.2788128
1922788128 are invalid.

Please let me know which method I should use then I will be able to do it.
Please help!
[ December 02, 2004: Message edited by: Nee Kat ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Report post to moderator
What have you done so far? You may find StringTokenizer to be helpful in parsing out each number that is separated by a period. Also, Integer has methods for converting a String to an int (assuming that the IP address is input as a String).

HTH

Layne
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Please don't post the same question to multiple forums -- it just wastes people's time. I'm going to close this one because this isn't really a beginner question, and leave this one open.
 
    Bookmark Topic Watch Topic
  • New Topic