Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created March 5, 2021 13:40
Show Gist options
  • Save swapnilshrikhande/1cf411c3d760629e239f949debae5b80 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/1cf411c3d760629e239f949debae5b80 to your computer and use it in GitHub Desktop.
Format SSN onkeyup
function(event) {
var val = event.target.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;
event.target.value = newVal;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment