Validating date in javascirpt

Ads
 

Validating date in javascirpt

View Answers

February 26, 2009 at 6:40 AM

Hi,

The following code may be useful for u.

<input type="text" id="usrdate" value=""/>

jscode:

var usrdate = document.getElementById("usrdate").value;//get user entered date
var usrdateArr = usrdate.split("--");//split the date by using '--' as token
var date = usrdateArr[0];//get date
var month = usrdateArr[1];//get month
var year = usrdateArr[2];//get year

//below if cond., is using to check the date is valid or not based on month
if((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)){
if(date<=0 && date>31){
alert("invalid date");
}
}else if(month == 2 && date<=0 && date>28){
alert("invalid date");
}else if(date<=0 && date>30){
alert("invalid date");
}

//below if cond., is using to check the month is correct or not
if(month<1 || month>12){
alert("invalid month");
}

//here year should not be less than 1.
if(year<1){
alert("invalid date");
}


regards,
siva kumar

Ads









Related Tutorials/Questions & Answers:
Validating XML
Validating XML  Hi, I have a string containing data in XML format. I have to Validate this xml data. Is there any method in java that allows strings as input to validate xml?   Please visit the following link: http
validating web pages
validating web pages  How to validate HTML web pages
Advertisements
Validating image size
Validating image size  How to validate image size to 2MB in javascript which is updating to mysql database
validating email id
validating email id  how to validate the email id ?   <html> <script> function validate(){ var e=document.getElementById('email').value; var regExpObj = /(\d\d\d)-\d\d\d\d\d\d\d\d/; var reg
date
date   how to insert date in database? i need coding
Validating the password field
Validating the password field  When the validate method returns back to the registration page the password field get cleared there by asking again one more time to enter the password field at the time of re-submitting the form
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
validating username and password from database
validating username and password from database  Hello sir, i am developing a login page. i want that when i fill data in text fields. it validate data from database. if enter data is match from database. page goes to next page
date
database table name birthday (DOB date); dob with DATE data type in database while...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try { System.out.println(date); Class.forName("oracle.jdbc.OracleDriver"); con
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
validating credentials and displaying error message in login .jsp if not valid
validating credentials and displaying error message in login .jsp if not valid  hi, i want to validate user name and password against my database table if not valid i have to display error message in my login page.how to do
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username and password in my servlet against database and if not valid want to display
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
javascript date validation using regex
;title>Validating Date format</title> <script type="text/javascript">...;Validating Date format</title> <script type="text/javascript">...javascript date validation using regex  Hi, I want to validate
date convertion
date convertion  How to convert the string date format 23/11/2009 to original date format in asp.net
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current  date. Understand with Example The Tutorial illustrate an example from 'DateTime
Java Date
Java Date  Hi, What is the API for Date management in Java? How use the Java Date API for manipulating date object in Java? Provide some... of API for working with date and time objects in Java. You can also use third
Date Picker
Date Picker  "I want to set default calendar date when using datepicker. This date means auto-loaded date when the calendar appears. The default date is the current date. I want to change it. How could I do
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
PHP Date
PHP Date  Hi, How to use PHP Date functions in my PHP program? Thanks   Hi, PHP Date functions is very handy. It is used to progracess, format and create date objects in PHP. There are many ways to use PHP Date
date function
date function  Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following 1. Display the day no from the date 2. Display the year from the date 3. Display
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance

Ads