Home Answers Viewqa Ajax regarding date field validation

 
 


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

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 Pages:
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
php date format validation
php date format validation  How to validate the date field in specific format in PHP
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
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
validation  please help me to check validation for <form>...;/tr> <tr> <td> <label>Date :</label> </td>...; <label> Date Picker</label>
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
Validation
; <b>Date of birth</b> :<input type="date" name="dob">
Validation
; <b>Date of birth</b> :<input type="date" name="dob">
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
Validation code - Java Interview Questions
Validation code  Hi, Anyone can please send me a javascript function for password filed validation (the field will only take characters as input... ************* Java Script Calender Date Picker function isNumberKey(value
spring form field clearence
in which i have security question and answer field for answer field validation after giving wrong format validation occurs but the field remains in that text field, I want clear the text field after validation occurs
Validation of datepicker
a future date is entered..How to do this validation in javascript or jsp...Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future
validation - Framework
validation  how to validate the action forms in struts? could you please explain how cross validation is done for date?  You go the following url: http://www.roseindia.net/struts/struts-login-form.shtml
Validation - Struts
Validation  How can i use validation framework i don't understand am...; Hi friend, Phone validation using javaScript function...==""){ alert ("This field is required. Please enter phone number without dashes
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
custom validation
custom validation  there are fields.if we fill in first field as 1.then next field only allow to fill a,b,c,d.other letters cannot enter.if enter send error.i used this method. frmvalidator.addValidation
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
regarding sending mesage - JavaMail
regarding sending mesage  i have tried the following program... MimeMessage(session); // Set the RFC 822 "From" header field using... field. message.setSubject("hi..!"); // Sets the given String
javascript validation
validation and for email field it will check formate useing regularexpressions...;html    Email Validation function checkEmail... your question properly..   validation for name it is useful try
alert for validation
data should be in DD/MM/YYYY format only through javascript validation.  ...) if (cpos1==-1 || cpos2==-1){ alert("The date format must be : dd/mm/yyyy...){ alert("Enter a valid date") return false } return
Struts 2 Validation (Int Validator)
annotations. Struts 2 default validation functions Following field validators are part...Struts 2 Validation (Int Validator)       Struts 2 Framework provides in-built validation functions to validate user
dob validation
dob validation  hi i am entering date, month and year in corresponding three drop down list. how to validate the date.....?   // validate...(); } function valid(dob1,dob2,dob3) { var daysInMonth = DaysArray(12) var date
javascript validation
button.. please send me the code for this as i am new to the dot net field
struts validation
struts validation  Sir i am getting stucked how to validate struts using action forms, the field vechicleNo should not be null and it should accept only integer values.can you help me please public ActionErrors validate
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
struts validation
struts validation  I want to apply validation on my program.But i am failure to do that.I have followed all the rules for validation still I am...;/label><html:file property="theFile" styleClass="upload_field" size="30
struts validation
struts validation  I want to apply validation on my program.But i am failure to do that.I have followed all the rules for validation still I am...;/label><html:file property="theFile" styleClass="upload_field" size="30
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code...)submit button All should display enter the field required(like name required,email required etc) &when i dont enter any field..& press submit button
Using Non Field Validators
Using Non Field Validators You can use non-field validators for server side validation in your application as. <validator type="expression"...; An Example using non field validators is goven below login.jsp <%@ taglib
Date limit on Dojo Date picker - Date Calendar
this validation by getting value from date picker text box or server side also, but I want this validation on dojo date picker only. User should not select date...Date limit on Dojo Date picker  Hi all, I am using dojo for date
HTML Form Validation example
HTML Form Validation example  Can anyone guide me how to validate the user name and password field in HTML using simple or JavaScript Validation. Thanks in advance!   <form method="post" onsubmit="return
server side validation in struts
server side validation in struts  Hello sir, i want to do server side validation in struts based on 3 fields. those 3 field are BatchNo,LotNo,StepNo.Here we can have the same batchno,lotno for different forms
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code for the following fields 1)Name 2)Email 3)Mobile 4)City 5)State 6)Product type 7)submit button All should display enter the field required(like name required
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.