I would like to do as they do that the fields input with type password can show the 4 characters, it is very common in the areas where you pay with a card, that you put your card and shows you the last characters or digits
I would like to do as they do that the fields input with type password can show the 4 characters, it is very common in the areas where you pay with a card, that you put your card and shows you the last characters or digits
How about, I did some tests and came up with the following result that I would like to share with you:
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="show.js"></script>
</head>
<body>
<p>Numero de tarjeta:</p>
<input type="text" maxlength="11" id="datos">
</body>
</html>
It is necessary to establish an encoding of utf-8 in the header, then add the library of JQuery and limit the maximum number of characters of the input to 11 as well as adding an id.
The show.js file contains jquery with the following code:
$(document).ready(function(){
var pActual = 0;
var cardNumber = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
var str = "";
var cnt = 0;
$("#datos").keyup(function(){
pActual = $(this).val().length;
var vActual = $(this).val();
vActual = vActual.substr(pActual-1, pActual);
if(pActual < 8){
for(var i = 0; i <= cardNumber.length-1; i++){
if(cardNumber[i] == vActual){
cnt = pActual;
if(cnt === pActual){
str += "•";
cnt += pActual;
}
$(this).val(str);
}
}
}
if($(this).val().length != cnt){
str = str.substr(0, pActual);
}
});
});
It reads as follows:
1.-When finished loading all the html execute a function
2.- Within the function declare 4 variables:
3.- In the selector with the id 'data' execute a function each time you press and release a key.
4.- Establishes pActual as the current length of the characters within the input.
5.- A variable called vActual is created that contains the last entered character.
6.- If the length of the characters in the input is less than 8 then:
7.- The string 'str' is shown inside the input
8.- If the current value of the input is not equal to the previous longitude counter 'cnt' then:
I hope it serves you.