Java JTextField Validation

Java JTextField Validation

Hello Sir ,How I can Validate JTextField In Java,when I enter Any Character value in JTextField ,I want To Display MsgBox ("Enter only Numeric Value") for Id Field ,How I can Validate that plz Help Me
View Answers

March 31, 2010 at 11:15 AM

Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;

class Validation extends JFrame{
JTextField text;
JLabel l1,l2;
JPanel p;
Validation(){
text=new JTextField(15);
l1=new JLabel("ID:");
l2=new JLabel("*Enter only Numeric Value");
p=new JPanel();
p.add(l1);
p.add(text);
p.add(l2);
l2.setVisible(false);
text.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input=text.getText();
Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()){
l2.setVisible(true);
l2.setForeground(Color.RED);
}
else{
l2.setVisible(false);
}
}
});
add(p);
setVisible(true);
setSize(300,100);
}
public static void main(String[]args){
Validation v=new Validation();
}
}

Thanks









Related Tutorials/Questions & Answers:
Java JTextField Validation - Java Beginners
Java JTextField Validation  Hello Sir ,How I can Validate JTextField In Java,when I enter Any Character value in JTextField ,I want To Display MsgBox... Validation extends JFrame{ JTextField text; JLabel l1,l2; JPanel p
float validation for jTextField
float validation for jTextField  Hi; I try that users enter only float number into jtextfield but I can not handle it. I try regex in keylistener but I couldn't be successful. Can you help me please
Advertisements
JTextField Validation in java swing
JTextField Validation in java swing In this tutorial, you will learn how to validate jtextfield in java swing. Here we have created a textfield on frame... extends JFrame{ JTextField text; JLabel label; JPanel p; TextValidation(){ text
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
JtextField - Java Beginners
JtextField  Hi, How can I populate a jtextfield of another Jframe...; JLabel label1,label2; JTextField text1,text2; Form() { label1 = new JLabel(); label1.setText("First Name:"); text1 = new JTextField(20
jtextfield
jtextfield  hii..is it possible to make a jtextfield in login page in such a way that some text should already be inserted like username and it should be displayed light in color and when a user enters some text then it should
JTextField
JTextField  simple program for text field cannot not be edited in java swing
jTextField in swing
jTextField in swing  I am new to java and i am making a registration form.i just want to know if there is any code in which a string cannot be inserted in a jtextfield where a phone number has to be inserted.the jtextfield should
Jlist and JTextfield
Jlist and JTextfield  How can we filter values from jlist by adding only a single letter in jtextfield such that when letter S is pressed in jtextfield then jlist should diplay all the values starting from letter S.I am using
Validation in swing - Java Beginners
Validation in swing  I want to validate my swing program. If I didnt enter the field in text box a msgbox should have to appear that enter all... JTextField text=new JTextField(15); JButton button=new JButton("Submit
validation
validation  validation
validation on dates - Java Beginners
validation on dates  how to find difference in days between two dates in java.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/java-get-example/number-days-between.shtml Thanks
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
How to return a string from a JTextField
How to return a string from a JTextField  Hi, Am new to java, and am trying to get a string from a JTextField so that I can compare it with another...(); final JTextField text=new JTextField(20); JButton b=new JButton
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation... TableEditor extends AbstractCellEditor implements TableCellEditor { JTextField
Validation
). How do i perform a check using JAVA on the data before storing...; JPanel panel; JLabel label1,label2; final JTextField text1,text2;; Form(){ label1 = new JLabel(); label1.setText("Email Id:"); text1 = new JTextField(20
validation in java script
validation in java script  i have put this code for only entering integer value in text box however error occured.. if(document.formname.textbox1.value!=="") { var rn,i; rn=document.formname.textbox1.value; for(i=0i='0' &
Admission Validation - Java Beginners
java.awt.event.*; class StudentAdmissionForm{ JTextField txt; public static void... JLabel("Name"); JTextField jt1=new JTextField(15); JLabel lbl2 = new JLabel("Address"); JTextField jt2=new JTextField(15); JLabel lbl3 = new JLabel("Gender
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
File format validation and text field validation in java swings
File format validation and text field validation in java swings   i am reading a jpg image file throuh jfilechooser in java swings,when we press browse button for selecting file it will display filechooser in this process when
Javascript validation - Java Beginners
Javascript validation  Hi I have developed the following function for the validation of Zip code,the problem is, when user enters the valid zip code in first attempt, the background color of text box changes to green while I
validation of date,phone number,email - Java Beginners
validation of date,phone number,email  Sir how to validate date,phone number and email in java swings  Hi Friend, Try the following code... Validations extends JFrame{ JLabel l1,l2,l3,l; JLabel lab1,lab2,lab3; JTextField
validation - Java Beginners
JavaScript validation file 'validation.js': function emailcheck(str
validation of strings using java function
validation of strings using java function  hi all, i am uploading data from csv file to data base where i took student id as string of length 6 char of the form abc123 will you please give me a function to validate this field
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Java User Validation
Java User Validation  Dear Deepak thanks for your help with my previous problem. I am looking to write a program that allows a user of a web... user in the database and add encrypted password(Please provide a java program
Copy data from one JTextField to another JTextField
Copy data from one JTextField to another JTextField..., you will learn how to copy the data from one JTextField into another JTextField. When you run this program it starts with two JTextField. Enter some
java script validation - Java Beginners
java script validation  hi, i have two radio buttons yea and no. all text fiels r deactivated, when i click no radio button. its get active... Button Validation function callEvent1
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page
java validation problem - JSP-Servlet
java validation problem  I have created a Registration page.I want validate the username entered by the user at the time he enters the username.How to do this? Can anyone gives the answer for this problem? Thanks in advance
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
easy way to make a JCombobox look like a JTextField?
easy way to make a JCombobox look like a JTextField?  Is there a good(and easy) way to make a JCombobox look like a JTextField? By this I mean.... works   Autosuggestion box in Java Swing
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page-- > <html:form action
Validation
Validation  Hi.. How to Validate blank textfield in java that can accepts only integers?   Have a look at the following link: http://www.roseindia.net/tutorial/java/swing/howtovalidatetextfield.html
validation
language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding
Email Validation code - Java Interview Questions
Email Validation code  Can anybody tell me how to write email validation code using java   Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java/core/regularExpressions.html Thanks
Validation code - Java Interview Questions
Validation code  Hi, Anyone can please send me a javascript function for password filed validation (the field will only take characters as input... ************* Java Script Calender Date Picker function isNumberKey(value
java script validation - Java Beginners
java script validation  how to do validations in j s p thru java script  Hi friend, Code to create a jsp page "contact.jsp" with javascript validation : Contact Details .txt { font-size:12px; font
javascript-email validation - Java Beginners
about email validation at: http://www.roseindia.net/jsp/valid-email-jsp.shtml
Credit Card Validation - Java Beginners
given by the instruction. here is the instruction: One validation algorithm
java struts validation - Java Server Faces Questions
java struts validation  i m unable to execute a validation page by struts . so please write u program and create a rar/jar file having all program with procedure and sand me . pls........ i m using bea weblogic 8.1 . my mail
Validation on input xml in java program - XML
Validation on input xml in java program  Hi.. i am accepting xml data as input which I have to use in my program. i have to validate this input xml against some schema using xml beans and NOT by using sax or dom parser. I am
Form Validation With Java Script
Form Validation With Java Script   ... the Validation in  JavaScript and  your Validation in JavaScript program. JavaScript  Java script is used to validate forms, that means checking the proper
update data to mysql database through JTextField
update data to mysql database through JTextField  I am getting an error, when i am updating a data to mysql database through JTextField. Send me the code used to solve my error. public void update(){ try
How to do Null validation for a boolean variable - Java Beginners
How to do Null validation for a boolean variable  How to do Null validation for a boolean variable in JAVA?  Hi friend, For solving the problem visit to : http://www.roseindia.net/java/master-java/variables
SWT_AWT bridge ,jtextfield edit problem - Swing AWT
SWT_AWT bridge ,jtextfield edit problem  Hi All, I am using SWT_AWT..._AWT bridge frame and adding JTextfield to it, My problem is that the JTextfield...(); JTextField textfield=new JTextField(); applet.add(textfield); frame.add(applet
Zip Code Validation - Java Interview Questions
function of the following --> Indian postal Zip Code Validation (Only 6 digits, no characters allowed) --> Date Validation (From and To) From date...://www.roseindia.net/javascript/ Thanks  Date Validation (From

Ads