Age Verification for Neutral Age Screen

Hello friends and welcome to Obsidian Soft,

Recently, one of my viewers commented on my video and queried about the age verification check in an app. So, this piqued my curiosity and I couldn’t stop myself from coding a short app for this purpose. The video tutorial might take some time as I have other tutorials in the pipeline but thought I should quickly put together a written tutorial for this problem. So, here it goes:

Start a new project in MIT App Inventor. I will name it AgeVerificationApp. I will check in this app if the user is 18 or not but you can change it to any year you want e.g. 13 for COPPA-compliant neutral age screens.

Design the screen by adding a DatePicker and Button from the User Interface Palette. Rename the datepicker to birthDatePicker and the button to submitBtn. Change the text on them accordingly.

Add a notifier from the user interface. Also, add a clock from the Sensors palette. Turn off the timer enabled checkbox as we just need the clock for getting the current date and not for running any timers.

This is what my screen looks like:


The components:


Go to the blocks section. Add a global variable for age.


Next, add a procedure from Procedures (use the one without the result). Rename to “calculateAge”. Keep it empty for the moment.


And call the procedure every time, the user changes his/her birth date.


Inside the submitBtn click event, add an if/else block from Control to check if the age is >= 18. Show alerts using the notifier accordingly. You can change this 18 number block to whatever age you want to verify against.


Last but not least, work on the custom procedure: calculateAge. Add a local variable within it.
Click on the clog wheel of the local variable and add 6 variables to it.
Once done, it will look similar to this:
Rename the first variable i.e. name to birthDay, x to currentDay, x2 to birthMonth, x3 to currentMonth, x4 to birthYear, and x5 to currentYear.
Now, assign them values accordingly by looking at how I am doing below:


Now, our logic is that if the current month is > than the birth month OR it is the same AND the current day is > = birthday then this means that the birthday has already passed so we can calculate age as current year minus birth year. In the other situation, the person’s age is current year minus birth year minus 1.



So, this is done and I hope you liked this short tutorial on an important topic i.e. verifying user-provided birthdate.

If you like my classes, consider supporting me by buying me a cup of coffee by pressing the button below:


I will publish a video tutorial soon.
Check out my other written tutorials for MIT App Inventor here.
Please like my social media pages for more educational resources and tips.
Pinterest:
https://www.pinterest.co.uk/obsidiansoft/_created/
For links to free educational apps, have a look at the educational apps page

Comments

Popular posts from this blog

Jolly Phonics Group 1

Jolly Phonics Group 2

Jolly Phonics Flash Cards