date time validation using javascript

Posted by Anishabathija under ASP.NET on 10/31/2012 | Points: 10 | Views : 3297 | Status : [Member] | Replies : 2
hey ,
could you help me with a code for date time validation ?

I found the corresponding code .

<script type="text/javascript" language="JavaScript">
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Torsten Frey () -->
<!-- Begin
function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
err = 0;
DateValue = DateField.value;
/* Delete all chars except 0..9 */
for (i = 0; i < DateValue.length; i++) {
if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
DateTemp = DateTemp + DateValue.substr(i,1);
}
}
DateValue = DateTemp;
/* Always change date to 8 digits - string*/
/* if year is entered as 2-digit / always assume 20xx */
if (DateValue.length == 6) {
DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
if (DateValue.length != {
err = 19;}
/* year is wrong if year = 0000 */
year = DateValue.substr(4,4);
if (year == 0) {
err = 20;
}
/* Validation of month*/
month = DateValue.substr(0,2);
if ((month < 1) || (month > 12)) {
err = 21;
}
/* Validation of day*/
day = DateValue.substr(2,2);
if (day < 1) {
err = 22;
}
/* Validation leap-year / february / day */
if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
leap = 1;
}
if ((month == 2) && (leap == 1) && (day > 29)) {
err = 23;
}
if ((month == 2) && (leap != 1) && (day > 2) {
err = 24;
}
/* Validation of other months */
if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
err = 25;
}
if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
err = 26;
}
/* if 00 ist entered, no error, deleting the entry */
if ((day == 0) && (month == 0) && (year == 00)) {
err = 0; day = ""; month = ""; year = ""; seperator = "";
}
/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
if (err == 0) {
DateField.value = day + seperator + month + seperator + year;
}
/* Error-message if err != 0 */
else {
alert("Date is incorrect!");
DateField.select();
DateField.focus();
}
}
// End -->
</script>


However in the client click property of the button I entered

OnClientClick="return check_date(field)();"

but when I run the program and enter www in the textbox field I get an error saying field value required rather than incorrect date.




Responses

Posted by: Hariinakoti on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
debug javascript with debugger.May be that date value not passed to that textbox field.
If u r using internet explorer 8 we can debug javascript easily.
after run the application u can press F12.that developer tools are opened and select script in that tool and put breakpoint and check step by step process like back end code.



Thanks & Regards
Hari

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kevinbenson on: 9/27/2014 [Member] Starter | Points: 25

Up
0
Down
You can buy a teenage boy a gift nowadays he or she will use and appreciate without spending half your salary to do this. It is expected for adolescent boys to desire the latest technology and would like to be equipped with the most high tech gadgets. But sometimes the funds don't allow this become reality. So instead of not buying them anything within or doing debt how about getting him something much more affordable and will be impressive as well.

To maintain our sanity, it is very important for american to de-stress, unwind and only let our hair down once in a while. There are different methods in one particular can de-stress and you should consider on the victim to a big extent. One very good method to de-stress to be able to travel.

Put utilized out can would love any shoes gift someone won't find their way to using to bunch on school supplies for the kids. Require http://www.the-fog.net/birkenstockcanada/birkenstock-sales.html gift for presents so you always have a ready supply to use as needed for supplies for your kids.

According to the Crazy 8 website, The Gymboree Corporation opened their first http://www.the-fog.net/birkenstockcanada/birkestock-for-men-stroe.html Crazy 8 store in 2007, which is sure to operates 37 stores your market United Suggests. They also have a website where shoppers can browse the past algorithm update fashions but have their purchases shipped directly to their living space. An added bonus is that Crazy 8 ships orders of all sizes for a designated rate of just $5!

This bet is aka as Straight Bet and 'en plein' in French and repays at 35 to just one. This bet is placed on only one number and also the http://www.the-fog.net/birkenstockcanada/birkenstock-for-men-online.html chip are going to placed in the center for this square.

Make the drawstring bag unique having a special features or emblem. Carefully consider monogramming the luggage or adding a sport motif applique or embroidery design prior to stitching. Position the design about 3 inches from backside in the guts of 1 of the 20 x 11 pieces.

"I can't do anything right. Why am I so foolish?" become the questions that publish instead of ones that turn your life around super fast. We've only covered the most elementary blocks of question asking, but can't you feel a little of the already? Hey, this helped take me from living on four wheels to standing on two little feet.



MayBe You Like:



http://www.oilandgasbmps.org/forums/viewtopic.php?f=10&t=8902

http://coolplayer.sourceforge.net/phorum/read.php?4,109845

http://www.nantes-wireless.org/forum/viewtopic.php?p=50444#50444

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response