javascript - Masking a social security number input -


for web application i'm building privacy important , format users input data.

to have inserted jquery library mask fields http://igorescobar.github.io/jquery-mask-plugin/

however, seem having trouble masking social security numbers. instance, format coming through nicely 567-78-7890, can't seem figure out how mask or hide first 4 numbers... *--7890.

my html input field

<input class='social' /> 

and plugin have tried masking as

$('.social').mask('000-00-0000'); 

this providing formatting

$('.newsocial').mask('xxx-xx-0000'); 

this replace numbers have entered x's.

i have set jsfiddle http://jsfiddle.net/w2sccqwy/1/

any wonderful!

p.s. cannot use password field because last 4 numbers have shown user , cannot have more 1 field. company requirement. cannot change company requirement as want to.

for might run in future able figure out solution mask kind of field , format without messing other plugin.

in html need 2 inputs

<input class='number' /> <input class='value' /> 

and position number field on value

and in javascript

 $('.value').on('keydown keyup mousedown mouseup', function() {      var res = this.value, //grabs value          len = res.length, //grabs length          max = 9, //sets max chars          stars = len>0?len>1?len>2?len>3?len>4?'xxx-xx-':'xxx-x':'xxx-':'xx':'x':'', //this provides masking , formatting         result = stars+res.substring(5); //this result      $(this).attr('maxlength', max); //setting max length     $(".number").val(result); //spits value input }); 

and jsfiddle see result. http://jsfiddle.net/gtom9tvl/


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -