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



Home Answers Viewqa Java-Beginners Validate JTexField with date on Text Changed event
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sushant
Validate JTexField with date on Text Changed event
1 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners


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

Advertisement
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
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
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
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
Text event in jsp
Text event in jsp  Hi I am doing project in jsp with mysql...="text/javascript"> function showData(value){ xmlHttp=GetXmlHttpObject() var url... 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
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
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>
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. Example Here I am giving a simple
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
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
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">
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"> <
long validate
long validate  How to validate long type
event handling
event handling  diff btwn event handling in ASP.net and in HTML
Check Date in PHP
Check Date in PHP The Checkdate() 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. Note
Display message on scroll Event
Display message on scroll Event In this tutorial, we will discuss about how to display message on scrolling of text area using jQuery scroll event. In this example, a text area with scroll bars are given , when we scroll any one
Event Listeners
Event Listeners  I want to learn the Event Listeners in Java. Any... is the good tutorial and example of Event Listeners in Java. Please check the tutorial Java - Event Listeners Example in Java Applet. Thanks
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
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" />
Event management
Event management   Hi, I want event management application like maintaining email notifications while task creation and update in broader way using spring java
Event in flex
Event in flex  Hi..... can you tell me about that How do you make component participate in event mechanism? Thanks   Ans: Extend EventDispatcher or any subclass of it or implement IEventDispatcher
Flex event
Flex event  Hi.... please tell me about How does Flex event system works? Thanks  Ans: When event are triggered there are three...: In the capturing phase, Flex examines an event target?s ancestors in the display list to see
Event in flex
Event in flex  Hi..... I want to know about What does calling preventDefault() on an event do? How is this enforced? please give me an example for that Thanks   Ans: The methods of the Event class can be used
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
Flex event
Flex event  hi...... How to capture and event if the component is disabled? please give an example..... Thanks in advance
Flex event
Flex event  Hi... please give me the answer with example What is event Bubbling? Thanks in advance  Event Bubbling: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex starts
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
date
date   how to insert date in database? i need coding
Advertisements
 

 

 

DMCA.com