Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to mask first Five digit number on keyup using *

Tags:

javascript

For eg while i am typing my ssn number my first 5 dight must be masked to *

  123456789    =>  *****6789

Note :on keyup it should check no of digits and mask based on it.

I came through this below example. It mask the entire nine digit.

https://codepen.io/anon/pen/VROrdo

like image 277
Robin Avatar asked Mar 27 '19 04:03

Robin


1 Answers

I modified your code to mask first 5 characters. Also this is bullet proof if someone paste a copied number.

https://codepen.io/anon/pen/PLvRWw

// Replace first 5 numbers with astericks
if (displayVal.length < 6){
  displayVal = displayVal.replace(/[0-9]/g, '*'); 
}
else{
  displayVal = '*'.repeat(5) + val.slice(5);
}
like image 143
Masoud Keshavarz Avatar answered Nov 10 '22 17:11

Masoud Keshavarz