regarding date field validation

regarding date field validation

View Answers

November 7, 2008 at 1:06 PM

Hi friend,

<html>
<title>date validation in javascript</title>
<head>

<script language = "Javascript">
var date= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if(bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary(year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
}
return this
}
function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(date)
var pos2=dtStr.indexOf(date,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(date,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, date))==false){
alert("Please enter a valid date")
return false
}
return true
}

function ValidateForm(){
var dt=document.frmSample.txtDate
if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}

</script>
</head>

November 7, 2008 at 1:07 PM

<body>
<br></br>
<center>
<table border="1" width="50%" bgcolor="pink">
<tr>
<td width="100%">
<form name="frmSample" method="post" action="" onSubmit="return ValidateForm()">
<h2><font color="red">Data Validation</font></h2>
<table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td> <p>Enter a Date <font color="#CC0000"><b>(mm/dd/yyyy)</b></font>
: </td>
<td>
<input type="text" name="txtDate" maxlength="10" size="20">
</p></td>
</tr>
<tr>
<td><center>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</center>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</center>
</body>
</html>

---------------------------------

Amardeep

Thanks









Related Tutorials/Questions & Answers:
regarding date field validation - Ajax
regarding date field validation  i have developed user information page for a site, all the fields are valid except date field. i want the date in dd... for this and thanks in advance.  Hi friend, date validation in javascript
Regarding struts validation - Struts
Regarding struts validation  how to validate mobile number field should have 10 digits and should be start with 9 in struts validation?  Hi friend
Advertisements
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
date validation
date validation  sir, pls provide date validation code in javascript..we want to include it into our master form..   Please visit the following link: http://www.roseindia.net/mysql/datevalidation.shtml
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
regarding out put display in html text field
regarding out put display in html text field  how to dispaly the output coming from servlet in a particular text field of html
php date format validation
php date format validation  How to validate the date field in specific format in PHP
Regarding Date Format - Java Server Faces Questions
Regarding Date Format  How I can convert this(18-Aug-08) date format to Gregorian calendar date format?plz send me the syntax and code plz!!  hai,, http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f
how to perform a validation for the field
how to perform a validation for the field  hi, function checkForm() { var getBank=document.form.bname.value; var alphaExp = /^[\,\ \-0-9a-zA-Z]+$/; var message=""; if(document.form.no.value
how to perform a validation for the field
how to perform a validation for the field  hi, function checkForm() { var getBank=document.form.bname.value; var alphaExp = /^[\,\ \-0-9a-zA-Z]+$/; var message=""; if(document.form.no.value
start date and end date validation in javascript - Ajax
start date and end date validation in javascript  hi, i am doing web surfing project. pls guide me for my project. i want start date and end validations in javascript. end date should be greater than start date if so less than
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
Mysql date field
Mysql date field       Mysql date field help you to create the data field and their respective data... an example to create date field in Mysql. The create table statement is used to create
How to Define Text Field Validation iPhone
How to Define Text Field Validation iPhone  Hi, Can anybody explain me how to define textfield validation iPhone program. please phone online help reference or example. Thanks
jquery start date end date validation
jquery start date end date validation  Using JQuery how can i validate the end date and start date? for example if the start date is grater than the end date?   jQuery.validator.addMethod("greaterThan", function(value
text field validation - Java Beginners
text field validation  hi How to validate allow only decimal number in text box in jsp?  Hi Friend, Try the following code: function isDecimal(str){ if(isNaN(str) || str.indexOf(".")<0){ alert
Date Field Midlet Example
Date Field MIDlet Example       This example illustrates how to insert date field in your form. We... and dateout field. For the specific date we are using here java.util.Date class
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
Date validation in JSP
Date validation in JSP       Example... how to use date validation in a JSP page. Here in this code we are using... things.  First, it is ensuring that input date field must not be empty
iPhone Text Field Validation
iPhone Text Field Validation In any user based application "... also Download the iPhone Text Field Validation code.  ADS_TO_REPLACE_8... data from user. In this tutorial we are going to limiting the text field input
validation of date,phone number,email - Java Beginners
validation of date,phone number,email  Sir how to validate date,phone... t1,t2,t3; JPanel p; Validations(){ l1=new JLabel("Enter Date: (MM/dd/yyyy... KeyAdapter() { public void keyTyped(KeyEvent e) { String date
php code: how to insert manual date and also retrieve records by selecting date field. - Date Calendar
php code: how to insert manual date and also retrieve records by selecting date field.  In PHP, how to insert user input date on mysql db. and also... to get the records by selecting date field in mysql. Please give me a correct code
Two Dates code validation - Date Calendar
fields which is Date of birth and date of joining.i want validate date of join should be greater than date of birth.plz help me in code .  Hi Friend... == "" || date2.value == "") alert("Enter date."); else alert("Date of joining
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
validation
validation  validation
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?  i want validation for one text field and text area,email,combobox, in that email will validte by useing
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
regarding rev
regarding rev  write a prog. in java that display all the arguments passed at the command line in reverse order
Regarding repository
Regarding repository  How to check in and check out using SVN repository using eclipse
date
date   how to insert date in database? i need coding
validation
validation  please help me to check validation for <form>...;/tr> <tr> <td> <label>Date :</label> </td>...; <label> Date Picker</label>
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
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
Regarding Hibernate
Regarding Hibernate  Both JDBC and Hibernate are used to connect to database then whats the need of going to hibernate? What are the main differences? And could you let me know please
Regarding Project
Regarding Project  sir, i am doing a project in java. my project is CITY GUIDE it is an web application. please give me documentation of my project
Regarding Project
Regarding Project  sir, i am doing a project in java. my project is CITY GUIDE it is an web application. please give me documentation of my project
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
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
Regarding javascript
Regarding javascript  Hi, I want 4 upload buttons in HTML CODE and Among 4 browse buttons user is not selected any one then provide a prompt message like plz select any 1 file among 4 buttons.If user is selected either 1st
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
Mysql Date Minimum
; Mysql Date Minimum return the minimum record value of a date field from... to find the minimum records value of a date field from a table 'employees'. To begin... out the minimum records or rows value of Date field Name 'date' as Min Date from
Regarding Datasource
Regarding Datasource  Hi friend, Good morning,how r u,i want to share 1 information to u,I got a job in VERIZON DATA SERVICES INDIA PVT.LTD,u help a lot when i am in academic project,with that project only i got a job
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container below that row itself and show the required details of the row
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
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation

Ads