jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes How to check the input string was an Hexadecimal number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to check the input string was an Hexadecimal number" Watch "How to check the input string was an Hexadecimal number" New topic
Author

How to check the input string was an Hexadecimal number

Qing Tian
Greenhorn

Joined: Aug 17, 2004
Posts: 10
Hi,
could someone can tell me How to check the input string was an Hexadecimal number.

String input = 3DF1
input was correct
else
input was incorrect display error message!

thanks
James Wang
Ranch Hand

Joined: Sep 04, 2003
Posts: 102
You may get the input string and compare every letter of it to 0..9, a..f and A..F, If every letter is in the scope above then it is correct string otherwise it is invalid.


James<br /> <br />SCJP,SCWCD,SCBCD,SCDJWS,SCEA
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
James W,

Welcome back to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We'd like something more than a single letter for the displayed last name.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Note that the Integer.parseInt() method comes in two flavors. One of them lets you specify a radix.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
String.matches("[\\dA-Fa-f]+") should work fine as well.

- Peter
Qing Tian
Greenhorn

Joined: Aug 17, 2004
Posts: 10
thanks for help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check the input string was an Hexadecimal number