aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Numeric/Alphabetic chars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Numeric/Alphabetic chars" Watch "Numeric/Alphabetic chars" New topic
Author

Numeric/Alphabetic chars

David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
Does the JDK have anything in the API for determining numeric vs. alpabetic characters? In my client, I prevent the user from typing anything but numbers for the fields that require numbers. But I do this by manually running through a string array of numbers (0 - 9) and checking each character typed via a KeyListener. If the character typed is not a numeric, then the KeyEvent is consumed. It works fine functionally, but is there anything in the JDK that would decipher numeric from alphabetic characters for me? I have not seen anything that would do this.
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi David,

If you want only to allow certain strings as valid input to a textfield, the standard way to achieve that, would be to use a JFormattedTextField with an appropriate AbstractFormatter-subclass or a Format-subclass.

Frans.


SCJP 1.4, SCJD
Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

Could you use a regular expression? Is using java.util.regex allowed on the SCJD? I have used regular expressions for stuff like this numerous times.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Numeric/Alphabetic chars
 
Similar Threads
How use number as ID (usable in IDREF)?
K&B Master Exam Regex Question
integer/numeric value of char
how to avoid special character in database?
String input with exceptions