Form Validation
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shanthy_Mani
Posted On:   Wednesday, February 27, 2002 06:53 PM

I have a form which has text fields for entering date.I am using a javascript function to validate the date(dd/mm/yyyy)The code is as follows: function validDate(formField,fieldLabel,required) { var result = true; if (required && !validRequired(formField,fieldLabel)) result = false; if (result) { var elems = formField.value.split("/"); result = (elems.length == 3); // should be three components if (result) { var month = parseInt(elems[1]); var day = parseInt(elems[0]); var year = parseInt(elems[2]); result = allDigits(elems[1]) && (month > 0) && (month < 13) &   More>>


I have a form which has text fields for entering date.I am using a javascript function to validate the date(dd/mm/yyyy)The code is as follows:


			function validDate(formField,fieldLabel,required)
			
{
var result = true;

if (required && !validRequired(formField,fieldLabel))
result = false;

if (result)
{
var elems = formField.value.split("/");

result = (elems.length == 3); // should be three components

if (result)
{
var month = parseInt(elems[1]);
var day = parseInt(elems[0]);
var year = parseInt(elems[2]);
result = allDigits(elems[1]) && (month > 0) && (month < 13) &&
allDigits(elems[0]) && (day > 0) && (day < 32) &&
allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
}

if (!result)
{
alert('Please enter a date in the format DD/MM/YYYY for the "' + fieldLabel +'" field.');
formField.focus();
}
}

return result;
}

			
function validateForm(theForm)
{
if (!validDate(theForm.txt_date,"Date",true))
return false;
}


This code is not validating the date.It accepts even if a wrong date is entered.
Can anyone tell me what is wrong with the code?

   <<Less

Re: Form Validation

Posted By:   irfan_mansha  
Posted On:   Wednesday, February 27, 2002 11:14 PM





A code from:http://javascript.internet.com/



Try it! be Cool
About | Sitemap | Contact