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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 24183
    
  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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IP Address format
 
Similar Threads
jboss-4.2.2.GA work with localhost but not work while i m using IP and port
IP Address Format
hi
iPlanet Webserver Problem : Listern Socket Table...
Java Regex