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 : firstname.lastname@example.org take care naina maraikar ------------------ WIN WITH LEAD!
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).]
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!