A birthday is the anniversary of the birth of a person which is celebrated in numerous cultures, often with birthday gifts, birthday cards, a birthday party, or a rite of passage.
There is a distinction between birthday and birth date: The former, other than February 29, occurs each year (e.g. January 20), while the latter is the exact date a person was born (e.g., January 20, 2001).
Why need to mask DOB?
Scammers, fraudsters, and identity thieves can wreak havoc with just your name, date of birth (DOB), and address.Fraudsters need just these three key bits of information to steal your identity and access your accounts, take out loans, credit cards, mobile phones in your name. These can be found on social media profiles, such as Facebook. And if your settings are not private or masked, this is available for anyone to see.
That’s what generally organizations while asking for date of birth masked years part or complete date so that not share by anyone except person working on web page.
There are different pattern to write date but here we mainly focus on most common used pattern (MM/dd/yyyy). According to your need you can modify example with respect to date pattern.
Date Patterns
- yyyy.MM.dd : 2001.07.01
- EEE, MMM d : Wed, Jul 4
- EEE, d MMM yyyy : Wed, 4 Jul 2001
- yyyy-MM-dd : 2001-07-01
- MM/dd/yyyy : 07/01/2001
- dd/MM/yyyy : 01/07/2001
See Also :
- Log4j2: How to Mask Logs Personal/Confidential/SPI Information
- How to Mask JSON Confidential/Personal Information in logs :JAVA
- How to mask JAVA Object confidential/personal information in logs while Printing
- How to MASK XML Confidential/Personal Data : JAVA
- How to mask Personal/Confidential Information on web page
DOB (Date of Birth) Masking Example
Here considering, date represent as MM/dd/yyyy. By masking will hide all digits except slaces. For example, Date is 06231987 than after formatting and mask will display as XX/XX/1987.
![]() | ![]() |
HTML Changes
Create a text box on your page with below html. Refer attachment
Java Script/JQuery Changes
Copy below java script in your head section of page.
var originalVal;
$(document).ready(function()
{
if($('#txtDOB').val().length>0)
{
if($('#txtDOB').val().indexOf("X")==-1)
{
originalVal=$('#txtDOB').val();
}
maskDOB(this);
}
$('#txtDOB').blur( function(e)
{
if($('#txtDOB').val().indexOf("X")==-1)
{
originalVal=$('#txtDOB').val();
}
maskDOB(this);
});
$('#txtDOB').focus( function(e)
{
$(this).val(originalVal);
});
});
function maskDOB(regularDOB)
{
var varlen =$(regularDOB).val().length;
if(varlen > 8)
{
$("#error").text('Not Valid Date.');
}
else
{
$("#error").text('');
var str = $(regularDOB).val();
var mask = varlen > 0 ? varlen > 1 ? varlen > 2 ? varlen > 3 ? varlen > 4 ? varlen > 5 ? varlen > 6 ? varlen > 7 ?
'XX/XX/'+ str.substring(4)
: 'XX/XX/'+ str.substring(4)
: 'XX/XX/'+ str.substring(4)
: 'XX/XX/'+ str.substring(4)
: 'XX/XX'
: 'XX/X'
: 'XX'
: 'X'
: '';
$(regularDOB).val(mask);
}
}
Note :
This masking example is created considering standard length of text size and formatting of text field, that can vary according to organizations. If your organization having different format and text size modify source code according to your need. If you are facing any issue drop a comments will try to connect as soon as possible.
Download Source code
To download the source code of this example, click on below given download link. Mask DOB
References
- https://defendingdigital.com/dont-share-your-birth-date-online/
- https://en.wikipedia.org/wiki/Birthday
Related Posts
Your Feedback Motivate Us
If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.
Happy Learning !!!
You must be logged in to post a comment.