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 how can i validate the ip address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can i validate the ip address" Watch "how can i validate the ip address" New topic
Author

how can i validate the ip address

ajay verma
Ranch Hand

Joined: Dec 10, 2007
Posts: 37
how can i validate the ip address.example are given below

10.02.0.99 is invalid
1.2.3.4.5.6 is invalid
109.2.8.06 is invaid

hint: with the help of String tokenize()
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19791
    
  20

First of all, 10.02.0.99 and 109.2.8.06 are perfectly valid. Just because they have an extra 0 doesn't mean they aren't valid. 109.2.8.06 is equal to 109.2.8.6.

Second, use String.split instead, using "\\." as the regex. The \\ will be resolved to a single \ for the regex, which is used to escape the .


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
give it a try,
if you need help, let us know,
post the code,


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can i validate the ip address