Anyone knows how to only allow characters in a JtextField not strings or digits? any example source code will be appreciated.
nilay84 0 Newbie Poster
Recommended Answers
Jump to PostWhat does "only characters... not strings" mean?
but whatever, here's one way
http://www.devx.com/tips/Tip/14311and the intro to the JavaDoc for JTextField shows another way - this one is an officially-approved approach
Jump to Post"there is only 2 ways"...
there's always another way...the one in JTextField's JavaDoc is neither of those (it extends the default model), but has the official stamp of approval.
Jump to Postoh it means that i should accept a b but not bd fg
Do you mean that the input can only be 1 character (or String of length 1), not any longer?
Jump to PostOK, parallel post with your improved def.
Do you want to check that when the user types into the field? When the user pastes into the field? When Java code changes the field's text? When focus leaves the field? When the user presses OK?
Jump to PostOK. In that case it's easiest just to validate the input when you need to use it. c0rthingy's edited version is a good place to start - test for the length being exactly 1, use charAt to get the one char from the String, then test that for being in …
All 21 Replies
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
nilay84 0 Newbie Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
nilay84 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
DavidKroukamp commented: not a prob man +6
DavidKroukamp 105 Master Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.