File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

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


IP Address should have periods at right places


are all valid entries where as

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).



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

Joined: Jul 08, 2003
Posts: 24199


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]
I agree. Here's the link:
subject: IP Address format
jQuery in Action, 3rd edition