In United States, Driving License is second social security identity after SSN. It should be hide and not shared with any one because having access to that one number can provide an identity thieft with several pieces of information they want to know about you.
Driving license numbers are alphanumeric values while the number of characters in driving license varies as per state.
- With Driving License card, someone knows your birthdate, address, and even your height, eye color, and signature.
- If someone gets your driver’s license number, it is also big concern because it’s connected to your vehicle registration and insurance policies, as well as records on file with the Department of Motor Vehicles, place of employment (that keep a copy of your driver’s license on file), doctor’s office, government agencies, and other entities.
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
Driving License Masking Example:
Here considering, driving license number of length 10 alphanumeric. By masking will hide initial 6 and characters show only last 4 characters. For example, my driving license number is ABC4567890 than after mask will display as XXXXXX7890.
![]() |
![]() |
HTML Changes
<b>Driving License Number:</b>
Create a text box on your page with below html.
Java Script/JQuery Changes
Copy below java script in your head section of page.
var originalVal; $(document).ready(function() { if($('#txtDLN').val().length>0) { if($('#txtDLN').val().indexOf("X")==-1) { originalVal=$('#txtDLN').val(); } maskDrivingLicenseNumber(this); } $('#txtDLN').blur( function(e) { if($('#txtDLN').val().indexOf("X")==-1) { originalVal=$('#txtDLN').val(); } maskDrivingLicenseNumber(this); }); $('#txtDLN').focus( function(e) { $(this).val(originalVal); }); }); function maskDrivingLicenseNumber(regularDLN) { var varlen =$(regularDLN).val().length; if(varlen > 10) { $("#error").text('Not Valid Driving License Number.'); } else { $("#error").text(''); var str = $(regularDLN).val(); var mask = varlen > 0 ? varlen > 1 ? varlen > 2 ? varlen > 3 ? varlen > 4 ? varlen > 5 ? 'XXXXXX'+ str.substring(6) : 'XXXXX' : 'XXXX' : 'XXX' : 'XX' : 'X' : ''; $(regularDLN).val(mask); } }
Download Source code
To download the source code of this example, click on below given download link.
Drop me your questions in comments section.
References