Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, October 19, 2009

Bith date validation with javascript

Hello All,

In one of my project I have to enter birth date.
BirthDateValidation function validates the BirthDate based on two conditions.

  1. The date should be less than or equal to the current date
  2. The date should be greater than current date and the difference between the current date and the date 100 years back.
So, right down the following code in your java script.
function BirthDateValidation()
{
var val=document.getElementById('birthdate').value;
var splits = val.split("/");
var dt = new Date(splits[1] + "/" + splits[0] + "/" + splits[2]);
var dtToday = new Date();
var pastDate = new Date(Date.parse(dtToday.getMonth()+"/"+dtToday.getDate()+"/"+parseInt(dtToday.getFullYear()-100)));
if (dt < pastDate || dt >= dtToday) {
alert("Birth Date can not be greatear than current Date"); }
else {
alert("valid BirthDate"); }
}

Write your Html code.
form name="validation" id="validation" method="post"
input name="birthdate" id="birthdate" type="text"
input name="btnsubmit" onClick="BirthDateValidation();" type="submit"
(formate dd/mm/yyyy

Simple you will get the right birth date. Better use calender instead of write birth date in textbox directly.

Sunday, June 8, 2008

Only enter integer value in textbox with javascript

Here the code how its work
create one php file as numberonly.php

write function into your javascript file
function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode <> 57))
return false;
return true; }

put this function into textbox onkeypress event.
input type=text onkeypress=return isNumberKey(this.value)
Enjoy.. you will get the result.