Validating a users age
Last Post 09-30-2013 05:27 AM by Ryan Bakerink. 1 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages Not Resolved
AlexUser is Offline
new to the springs
new to the springs
Posts:1
Avatar

--
09-25-2013 08:53 PM
    Hello, we have a custom profile property named "DOB", and we have Dynamic Registration writing into that perfectly using the 3 dropdowns (day, month, year).

    How is it possible to validate a date within Dynamic Registration? We want to make sure that a user is at least 18 years old.

    Can this be done? Could you give a small example to point me in the right direction please?

    Thanks!
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    09-30-2013 05:27 AM
    Hello Alex,

    There are 2 different ways in which you can perform this validation:

    * SQL Validation
    * JavaScript (on Client Side Event)

    It really depends on how you'd like to handle this validation, on the client side or server side. Client side is usually a more elegant solution for this type of validation.

    I would recommend trying the following JavaScript function that I found on the web:

    ---------------------------------------
    function getAge(dateString) {
    var today = new Date();
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }
    ---------------------------------------

    Add this function to Module Configuration -> Advanced Coding Options -> Custom JavaScript file -> JavaScript file.

    Be sure to completely refresh your webpage after saving this function and exiting the admin configuration interface.


    There are a couple things to note. If the validation fails, you'll probably want to inject informative text into a span or label using innerHTML , and you'd probably want to disable/hide the submit button until this validation is satisfied. If the validation passes, you'll want to clear the informative text in the span/label and display/enable the submit button.

    Please let us know if you have any questions.

    Thanks,

    Ryan




    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi