屏蔽输入任何字段和值 [英] Masking inputs any field and values
问题描述
我想知道如何获得输入的长度,并在开始和结束值之间替换所有内容,但留下2个字符和两端。
我不知道我不希望预定义长度,因为我希望它能够处理任何具有任何值的输入,并且仍然能够在提交表单时使用PHP读取值。
输入: Hello world street 12
输出: He *** *** ** ****** 12
输入: 185445414631
输出: 18 ******** 31
Js lib:
https:/ /github.com/igorescobar/jQuery-Mask-Plugin
我的代码:
https://jsfiddle.net/k4y0ctho/1/
如果您的输出是在其他领域可以接受,这可能是有用的
< script src =https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js> < / script>< input type =passwordid =input/>< br>< span id =output>< / span>
I would like to know how to get the length of an input and replace everything between the values start and end but leave 2 chars and both ends.
I don't want to predefine the length as I want it to work on any input with any value and still be able to read the values with PHP when form submitted.
Input: Hello world street 12
Output: He*** ***** ****** 12
Input: 185445414631
Output: 18********31
Js lib: https://github.com/igorescobar/jQuery-Mask-Plugin
My code: https://jsfiddle.net/k4y0ctho/1/
if your output is acceptable on other field, this might be useful
$("#input").on("keyup", function() {
var input = $(this).val().split("")
var res = $.map(input, (el, ix) => {
return ix < 2 || ix > input.length - 3? el:"*"
})
$("#output").html(res.join(""));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="password" id="input" />
<br><span id="output"></span>
这篇关于屏蔽输入任何字段和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!