age calculation

age calculation

pls send me the age calculation validation coding in java script. i'm waiting for ur reply...

View Answers

July 13, 2012 at 11:00 AM

The given javascript code calculates the age of a person. Here we have used regular expression to validate date format. If inputted date of birth is in form of dd/mm/yyyy then count age by subtracting dob into current date. you can also take specified date in place of current date to count age. getFullYear() is used here to get year of specified date.

<html>
    <head>
    <script type="text/javascript">
        function ageCount() {
            var date1 = new Date();
            var  dob= document.getElementById("dob").value;
            var date2=new Date(dob);
            var pattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Regex to validate date format (dd/mm/yyyy)
            if (pattern.test(dob)) {
                var y1 = date1.getFullYear(); //getting current year
                var y2 = date2.getFullYear(); //getting dob year
                var age = y1 - y2;           //calculating age 
                document.write("Age : " + age);
                return true;
            } else {
                alert("Invalid date format. Please Input in (dd/mm/yyyy) format!");
                return false;
            }

        }
    </script>
    </head>
    <body>
    Date of Birth(dd/mm/yyyy):
    <input type="text" name="dob" id="dob" />
    <input type="submit" value="Age" onclick="ageCount();">
    </body>
    </html>

Ads









Related Tutorials/Questions & Answers:
age calculation
age calculation  pls send me the age calculation validation coding in java script. i'm waiting for ur reply
calculation
Advertisements
tax calculation
tax calculation  I want you to write a program while take some amount and do the tax calculation Sr.No. Particulars Present Rate Amount in INR 1 Service Fee - 100 2 Service tax Tax 12.00% 12 Education cess
age calculator
age calculator  sir , actually m working on a project where i want the user to enter his date of birth in a jtextfield .and on doing so his age should b displayed in the next textfield automatically....plz help
ModuleNotFoundError: No module named 'calculation'
ModuleNotFoundError: No module named 'calculation'  Hi, My Python... 'calculation' How to remove the ModuleNotFoundError: No module named 'calculation' error? Thanks   Hi, In your python environment
Average Age of my Class?
Average Age of my Class?  average age of my class
Total Hours Calculation.
Total Hours Calculation.   Hi,How to calculate the total hours by startime and endtime.not railway time just only normal time.please help. Thanks
ModuleNotFoundError: No module named 'age'
ModuleNotFoundError: No module named 'age'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'age' How to remove the ModuleNotFoundError: No module named 'age' error
ModuleNotFoundError: No module named 'refund_calculation'
ModuleNotFoundError: No module named 'refund_calculation'  Hi, My... named 'refund_calculation' How to remove the ModuleNotFoundError: No module named 'refund_calculation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'simplex_calculation'
ModuleNotFoundError: No module named 'simplex_calculation'  Hi, My... named 'simplex_calculation' How to remove the ModuleNotFoundError: No module named 'simplex_calculation' error? Thanks   Hi
ModuleNotFoundError: No module named 'Solar-Calculation'
ModuleNotFoundError: No module named 'Solar-Calculation'  Hi, My... named 'Solar-Calculation' How to remove the ModuleNotFoundError: No module named 'Solar-Calculation' error? Thanks   Hi, In your
calculation after if. user input
calculation after if. user input  System.out.print ("please select one of the following by pressing tne number on your keypad"); System.out.println(); System.out.println("1. Apples"); System.out.println("2. Oranges
Artifacts of com.clever-age
List of Artifacts of com.clever-age maven depenency
Calculate an average Age of my Class?
Calculate an average Age of my Class?  average age of my class
Version of com.clever-age>play2-elasticsearch dependency
Is there any age limit for data scientist?
Is there any age limit for data scientist?  Hi, I am beginner... to learn: Is there any age limit for data scientist? Try to provide me good examples or tutorials links so that I can learn the topic "Is there any age limit
ModuleNotFoundError: No module named 'age-and-weight-Converter'
ModuleNotFoundError: No module named 'age-and-weight-Converter'  Hi...: No module named 'age-and-weight-Converter' How to remove the ModuleNotFoundError: No module named 'age-and-weight-Converter' error? Thanks  
ModuleNotFoundError: No module named 'mpi-age-aegis'
ModuleNotFoundError: No module named 'mpi-age-aegis'  Hi, My... 'mpi-age-aegis' How to remove the ModuleNotFoundError: No module named 'mpi-age-aegis' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age'  ...: No module named 'odoo10-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-age'  ...: No module named 'odoo11-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-age' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age'  ...: No module named 'odoo12-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age' error
ModuleNotFoundError: No module named 'odoo12-addon-partner-age'
ModuleNotFoundError: No module named 'odoo12-addon-partner-age'  Hi...: No module named 'odoo12-addon-partner-age' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-partner-age' error? Thanks  
ModuleNotFoundError: No module named 'odoo12-addon-partner-age'
ModuleNotFoundError: No module named 'odoo12-addon-partner-age'  Hi...: No module named 'odoo12-addon-partner-age' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-partner-age' error? Thanks  
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-age'  ...: No module named 'odoo8-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-age' error? Thanks
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age'  ...: No module named 'odoo10-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-age' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age'  ...: No module named 'odoo12-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-age' error
ModuleNotFoundError: No module named 'odoo13-addon-hr-employee-age'
ModuleNotFoundError: No module named 'odoo13-addon-hr-employee-age'  ...: No module named 'odoo13-addon-hr-employee-age' How to remove the ModuleNotFoundError: No module named 'odoo13-addon-hr-employee-age' error
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?  how to done calculation for dynamic generated textboxes in jquery/javascript/ajax
ModuleNotFoundError: No module named 'odoo8-addon-product-template-book-weight-calculation'
-calculation'  Hi, My Python program is throwing following error...-weight-calculation' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-product-template-book-weight-calculation' error? Thanks
JavaScript calculate age from date of birth
JavaScript calculate age from date of birth  How to calculate age...(); //getting dob year var age = y1 - y2; //calculating age document.write("Age : " + age); return true; } else
What age should you start a career?
What age should you start a career?  Hi, I am beginner in Data...: What age should you start a career? Try to provide me good examples or tutorials links so that I can learn the topic "What age should you start a career

Ads