aspose file tools*
The moose likes Beginning Java and the fly likes IP Address format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

IP Address format

Nee Kat
Ranch Hand

Joined: Jan 27, 2004
Posts: 37
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IP Address format