Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input rules on a TJext area

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
Hi all.

I want users to be able to enter numbers (only) into a text box (JText) and an action to be taken for when the user presses enter.

I.e. enters 3543 and presses enter, will implement a method.

I could do this in VB or HTML, but not in Java (am new). Can anyone help?
 
Here's a couple of ideas:

1. The String class has a method called matches() which takes a RegExp value to validate its type. If you know RegExp, or look on the web for RegExps for validating numbers, you could find the expression you want and use it to validate your code.

2. The Integer class has a method called getInteger() which takes a String as its argument. If the String cannot be converted into an integer, the method returns null. Otherwise, it returns an Integer object. While this might work, you'd have to keep negative numbers in account for what you want to do.

Personally, I think (1) would probably be the best choice.

Hope this helps.

Nick Ruiz
Webmaster, DBA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top