Validate JTexField with date on Text Changed event

Hello Sir I want to only Validate date in MM/DD/YYYY Format on TextChanged Event,date will automatically set through MM with two digits,then cursor will automatically set to next DD of Two digits and same as year of four digits within one JTextField and also have onTextChanged Validation ,plz Help me sir
View Answers

April 10, 2010 at 11:53 AM

Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
class Validations extends JFrame{
JLabel l1,l2,l3,l;
JLabel lab1,lab2,lab3;
JTextField t1,t2,t3;
JPanel p;

Validations(){
l1=new JLabel("Enter Date: (MM/dd/yyyy)");
t1=new JTextField(20);

lab1=new JLabel();

p=new JPanel(new GridLayout(2,2));
p.add(l1);
p.add(t1);
p.add(lab1);
add(p);
setVisible(true);
pack();
lab1.setVisible(false);
t1.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String date=t1.getText();
if(isValidDate(date)){
lab1.setVisible(false);
}
else{
lab1.setText("* Invalid date");
lab1.setForeground(Color.red);
lab1.setVisible(true);
}
}
});

}
public boolean isValidDate(String inDate) {

if (inDate == null)
return false;
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dateFormat.setLenient(false);
try {
dateFormat.parse(inDate.trim());
}
catch (ParseException pe) {
return false;
}
return true;
}
public static void main(String[]args){
Validations v=new Validations();
}
}

Thanks









Related Tutorials/Questions & Answers:
Validate JTexField with date on Text Changed event - Java Beginners
Validate JTexField with date on Text Changed event  Hello Sir I want to only Validate date in MM/DD/YYYY Format on TextChanged Event,date...; Validations(){ l1=new JLabel("Enter Date: (MM/dd/yyyy)"); t1=new JTextField(20
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript... if (!validformat.test(input.value)) alert('Invalid Date Format. Please correct.') else{ //Detailed check for valid date ranges var
Advertisements
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
JQuery date change event
JQuery date change event  JQuery date change event I have been... date and end date for any event. I have already writen a function that allows... = 6; then my end date must be changed to 7 Jan 2013
Text event in jsp
Text event in jsp  Hi I am doing project in jsp with mysql...;script type="text/javascript"> function showData(value){ xmlHttp...;td> <input type="text" name="name" id="name" onkeyup="showData(this.value
Text box control--keypress event
Text box control--keypress event  In my form have a text box...My requirement is... when is type characters in that box... before typing the 3rd character the space should come automatically or programmatically...the sturucture
ModuleNotFoundError: No module named 'recognizers-text-date-time'
ModuleNotFoundError: No module named 'recognizers-text-date-time'  Hi...: No module named 'recognizers-text-date-time' How to remove the ModuleNotFoundError: No module named 'recognizers-text-date-time' error? Thanks
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot apply date greater than 31/03 of particular year. So, if the user apply the date
ModuleNotFoundError: No module named 'odoo11-addon-website-event-questions-free-text'
-website-event-questions-free-text' error? Thanks   Hi... odoo11-addon-website-event-questions-free-text python with following command: pip install odoo11-addon-website-event-questions-free-text After
ModuleNotFoundError: No module named 'odoo12-addon-website-event-questions-free-text'
-website-event-questions-free-text' error? Thanks   Hi... odoo12-addon-website-event-questions-free-text python with following command: pip install odoo12-addon-website-event-questions-free-text After
javascript cal code for selecting date in text field - JSP-Servlet
javascript cal code for selecting date in text field  HI I want javascript calendar code to select date in text field in jsp.pls send me?  Hi Friend, Please visit the following links: http://www.roseindia.net
Javascript get Date And Selected Option Text
Javascript get Date And Selected Option Text In this tutorial we will learn... explains you that how to display the date and the selected option text in Javascript... the date and the selected option text into HTML. ExampleADS_TO_REPLACE_1 Here I am
ModuleNotFoundError: No module named 'changed'
ModuleNotFoundError: No module named 'changed'  Hi, My Python... 'changed' How to remove the ModuleNotFoundError: No module named 'changed... to install padas library. You can install changed python with following command
Display current date in text box in JSP using javascript
Display current date in text box in JSP using javascript In this section you will learn how to display current date in text box using JavaScript.For...();"> Today's Date is: <input type="text" id="datetext"
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
ModuleNotFoundError: No module named 'when-changed'
ModuleNotFoundError: No module named 'when-changed'  Hi, My Python... 'when-changed' How to remove the ModuleNotFoundError: No module named 'when-changed' error? Thanks   Hi, In your python
Validate TextArea
Validate TextArea       In this section, you will learn how to validate your text area in struts 2. A text area contains 1 to 250 characters. It cann't support
Check Date in PHP
Check Date in PHP The Checkdate()ADS_TO_REPLACE_1 The PHP Checkdate function is used for validating the system date. It validate the Gregorian date. It returns 'True' if finds the specified date valid, otherwise it returns false
date
database table name birthday (DOB date); dob with DATE data type in database while..., ParseException { response.setContentType("text/html;charset=UTF-8...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try
date
date   how to insert date in database? i need coding
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
long validate
long validate  How to validate long type
DATE
DATE  I have the following as my known parameter Effective Date... of calcultion starts My question is how to find the date of Thursday This cycle... the date of all the thursdays of the given year. import java.util.*; import
ModuleNotFoundError: No module named 'docker-push-latest-if-changed'
ModuleNotFoundError: No module named 'docker-push-latest-if-changed'  ...: No module named 'docker-push-latest-if-changed' How to remove the ModuleNotFoundError: No module named 'docker-push-latest-if-changed' error
ModuleNotFoundError: No module named 'django-changed-fields'
ModuleNotFoundError: No module named 'django-changed-fields'  Hi...: No module named 'django-changed-fields' How to remove the ModuleNotFoundError: No module named 'django-changed-fields' error? Thanks   Hi
ModuleNotFoundError: No module named 'docker-push-latest-if-changed'
ModuleNotFoundError: No module named 'docker-push-latest-if-changed'  ...: No module named 'docker-push-latest-if-changed' How to remove the ModuleNotFoundError: No module named 'docker-push-latest-if-changed' error
javascript regex validate url
regex</title> <script type="text/javascript"> function validate...javascript regex validate url  How to validate URL in regex...;Validating Url..</h2> Url : <input type="text" name="url" id="url" />
JavaScript regex validate Telephone no.
JavaScript regex validate Telephone no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var phone = document.getElementById("phone").value
continue java - Date Calendar
continue java  How to make a subtract date from jframe like jtexfield, data can input into jtextfied ? and how to get year, yesterday a have a question about how to substract dd mm yyyy can in this subtract have a year.thank
javascript regex validate currency
javascript regex validate currency  How to validate currency... using regex</title> <script type="text/javascript"> function validate() { var currency = document.getElementById("currency").value
JavaScript regex validate Mobile no.
JavaScript regex validate Mobile no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var mobile = document.getElementById("mobile").value
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
Date validation
Date validation  How to validate date in jsp? That is i have a textbox which will have the value from the date picker. How to validate the date that should be entered in a specified format?   Hi Friend, Please visit
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
php date format validation
php date format validation  How to validate the date field in specific format in PHP
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate...;title>Validating Date format</title> <script type="text/javascript"> function validate() { var date = document.getElementById("date
Date limit on Dojo Date picker - Date Calendar
Date limit on Dojo Date picker  Hi all, I am using dojo for date picker in my project. When user click on date text box, date picker will pop up... this validation by getting value from date picker text box or server side also, but I
validate email objective c
validate email objective c  how can i validate email text field in objective c? is there any method that support multiple email address separated by coma.   - (BOOL)validateEmailWithString:(NSString*)email
Validate telnet connectivity
Validate telnet connectivity  How to validate telnet connectivity in my java code
validate bank account number
validate bank account number  how to validate bank account number in jsp