Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java JTextField Validation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shweta
Java JTextField Validation
1 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners


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

Advertisement
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
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
Advertisements
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
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 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 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 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
validation
validation  validation
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 - Java Beginners
JavaScript validation file 'validation.js': function emailcheck(str
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
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
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
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
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
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
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  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
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
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
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 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
Advertisements
 

 

 

DMCA.com