0

I have a SharePoint Date Picker Control which is used to select a BirthDate . I want the birthdate to be atleast 16years older from the current date.

Can anyone guide me how to validate this using javascript? I have not used javascript much, Please guide me how to go about the validation process?

1

1 Answer 1

1

Look at using the library date.js:-

http://www.datejs.com/

This library adds a number of methods for working with date objects.

Without using an external library, the easiest way to compare a date of birth is over 16 is to convert the date to an epoch timestamp and then compare this against a timestamp of now minus 16 years.

Be aware that while most languages/platforms use timestamps in seconds, Javascript uses milliseconds, so when comparing against timestamps from external sources, you need to divide by a factor of 1000.

Sign up to request clarification or add additional context in comments.

2 Comments

Just don't come back to SO when you sued over some underage user using your service just because he had 3 days to his 16th birthday on registering and you didn't bother to take leap years in account.
@Oleg Using a library you would convert the current date 16 years ago to your comparison timestamp rather than subtracting 16 years worth of seconds from a current timestamp. Without a library, yup, you must calculate leap days and leap seconds yourself, your note of caution is well placed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.