T
T
townee2018-05-17 10:51:45
iPhone
townee, 2018-05-17 10:51:45

Why does iphone skip age verification?

Hello!
I can't understand why iphone doesn't take into account the condition, but android does.
I have the following check for age

var bDay = ""+yearVal+"-"+monthVal+"-"+dayVal+"";
var checkAge = Math.floor((new Date().getTime() - new Date(bDay)) / (24 * 3600 * 365.25 * 1000));
if(checkAge < 18) {
    $(".error").show();
        return;
}

The problem is only on iPhones, it skips this check and moves on, what could be causing it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-05-17
@alexalexes

a) In order to avoid misunderstandings with the date format of the input string, substitute the parameters explicitly: b) It is also useful to reduce the time to one value for comparison:
PS: In general, the age must be calculated for each component of the date, so as not to run into leap years:

var now = new Date();
var age = (now.getFullYear() - yearVal - ((now.getMonth() - (monthVal - 1) || now.getDate() - dayVal) < 0 ? 1 : 0));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question