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



Home Answers Viewqa Ajax regarding date field validation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jeeva
regarding date field validation
2 Answer(s)      6 years and 2 months ago
Posted in : Ajax



Advertisement
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
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
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
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
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
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
Mysql date field
Mysql date field       Mysql date field help you to create the data field and their respective data... date field in Mysql. The create table statement is used to create a table
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
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
iPhone Text Field Validation
iPhone Text Field Validation In any user based application "... Field Validation code.  ... data from user. In this tutorial we are going to limiting the text field input
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
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">
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
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...; First, it is ensuring that input date field must not be empty. Second, date
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
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  validation
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
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
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
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
Advertisements
 

 

 

DMCA.com