By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,646 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,646 IT Pros & Developers. It's quick & easy.

I want to know symbols validation in JTextField using java swing

P: 1
what i want to do is when we are going to type something inside the text field, it should not allowed symbols ...

the code i used

Expand|Select|Wrap|Line Numbers
  1.  if (evt.getKeyChar()=='&'||evt.getKeyChar()=='@') {
  2.        jTextField2.setText("");
Nov 16 '12 #1
Share this Question
Share on Google+
1 Reply

P: 126
Expand|Select|Wrap|Line Numbers
  2. String input=jTextField2.getText();
  3. Pattern p = Pattern.compile("[&%$#@!()*^]");
  4. Matcher m = p.matcher(input);
  5. if (m.find()){
  6. jTextField2.setText("");
  7. }
Nov 16 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.