Alan Smith
Alan Smith

Reputation: 1169

Validate MAC and IP addresses in Java

I am writing a program to read in data from an excel sheet which contains a bunch of info about computers which will be entered by the user. This excel file will then be converted to a different format for other uses. I can read all the values no problem but I just need help validating MAC and IP addresses entered by the user to make sure the information is correct. Some regular expressions for this would be great as I am sure I would use them again at some stage.

Thanks.

Upvotes: 0

Views: 4510

Answers (2)

muthukumar
muthukumar

Reputation: 2243

([0-9A-F]{2}[:-]){5}([0-9A-F]{2})

This is for mac address

Upvotes: 1

Giordano Maestro
Giordano Maestro

Reputation: 341

 "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"

Upvotes: 1

Related Questions