Jump to content

Input Mask Ssn Social Security Number


Recommended Posts

Try this

<SCRIPT LANGUAGE="JavaScript">

function f_a(v_id)
{
return document.getElementById(v_id);
}

f_a('FIELDID').maxLength = 11;

f_a('FIELDID').onkeyup = function(v_e)
{
v_e = v_e || window.event;

if (v_e.keyCode >= 65 && v_e.keyCode <= 90){
	this.value = this.value.substr(0, this.value.length - 1);   
	return false;
}else if (v_e.keyCode >= 37 && v_e.keyCode <= 40){
	return true;
}

var v_value =(this.value.replace(/[^\d]/g, ''));   

if(v_value.length==9){
this.value = ( v_value.substring(0,3) + "-" + v_value.substring(3,5) + "-" + v_value.substring(5,9)); 
};
}

</script>

Replace FIELDID with SSN Field ID

Link to comment
Share on other sites

  • 5 years later...

Hello, 

I also have a short script that will mask SSN value in a Details Page.

<script>

var account = document.getElementById('EditRecordSSN');

account.value = new Array(account.value.length-3).join('x') + 
account.value.substr(account.value.length-4, 4);

</script>

Replace SSN in EditRecordSSN depending on the correct field name in the Table. 

 

Cheers!

Link to comment
Share on other sites

  • 1 year later...

Hi! If you would like to automatically format SSN/Social Security Number in the Text Field, you can try these solutions:

1. From this link: https://stackoverflow.com/questions/7685175/autoformat-ssn-while-entering-the-number#:~:text=at 0%3A25-,Karl Keefer,-6361 - JavaScript

Applying in the DataPage's Footer with this code:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

function formatSSN(ssn) {

  // remove all non-dash and non-numerals
  var val = ssn.replace(/[^\d-]/g, '');

  // add the first dash if number from the second group appear
  val = val.replace(/^(\d{3})-?(\d{1,2})/, '$1-$2');

  // add the second dash if numbers from the third group appear
  val = val.replace(/^(\d{3})-?(\d{2})-?(\d{1,4})/, '$1-$2-$3');

  // remove misplaced dashes
  val = val.split('').filter((val, idx) => {
    return val !== '-' || idx === 3 || idx === 6;
  }).join('');

  // enforce max length
  return val.substring(0, 11);

}

// bind our function
document.getElementById("InsertRecordSSN").onkeyup = function(e) {
  this.value = formatSSN(this.value);

}

});

</script>

2. https://stackoverflow.com/questions/7685175/autoformat-ssn-while-entering-the-number#:~:text=at 6%3A20-,Jason Hansen,-33 - jQuery
 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

 $('#InsertRecordSSN').keyup(function() {
          var val = this.value.replace(/\D/g, '');
          var newVal = '';
          if(val.length > 4) {
             this.value = val;
          }
          if((val.length > 3) && (val.length < 6)) {
             newVal += val.substr(0, 3) + '-';
             val = val.substr(3);
          }
          if (val.length > 5) {
             newVal += val.substr(0, 3) + '-';
             newVal += val.substr(3, 2) + '-';
             val = val.substr(5);
           }
           newVal += val;
           this.value = newVal.substring(0, 11);
        });

});

</script>

3. By using Cleave JS - https://nosir.github.io/cleave.js/

<script src="https://cdnjs.cloudflare.com/ajax/libs/cleave.js/1.6.0/cleave.min.js"></script>

<script>

var cleave = new Cleave('#InsertRecordSSN', {
    delimiter: '-',
    blocks: [3,2,4],
    numericOnly: true
});

</script>

Take note that you need to change the InsertRecordSSN based on your right field name. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...