aspose file tools*
The moose likes Applets and the fly likes Textbox-validation! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Textbox-validation!" Watch "Textbox-validation!" New topic
Author

Textbox-validation!

Naina maraikar
Greenhorn

Joined: Nov 08, 2000
Posts: 1
dear winners..
fine and praying the same.
i mail this to clearify me how to create two textboxes which were validated as such one box should allow to enter only numbers and other to enter only Strings.
it will be much thankful to get me informed .
mail id : maraikar@hotmail.com
take care
naina maraikar
------------------
WIN WITH LEAD!


WIN WITH LEAD!
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I'm not too sure of exactly what you want to test for here but I'll give it a try .
For a "number only" TextField (I'm assuming 'textbox' means this and not a TextArea) simply get the textfield entry using myTextField.getText() and then try to parse it to an int. If you get an NumberFormatException, send the user the appropriate message.For example,

For the "string only" TextField, I have two solutions depending on what you want. If it simply means 'not a number' then do the opposite of the above. Meaning, get the String and if you *can* parse it to an int then it's not a String. However, if you mean absolutly no numbers contained within the entire String (ie. when4we56go is illegal) then you'll have to examine each character at a time. To do this, here are some suggested steps.
1) get the text from the TextField
2) create a Reader like so Reader r = new StringReader( inString);
2) loop though each character and compare it to the range of acii value for numbers. For example,

I haven't tested this code but you get the idea. Hope this helps.
Sean


[This message has been edited by Sean MacLean (edited November 10, 2000).]
[This message has been edited by Sean MacLean (edited November 10, 2000).]
 
Don't get me started about those stupid light bulbs.
 
subject: Textbox-validation!