• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Textbox-validation!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
author
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic