用户输入时每5个字符插入' - '[如产品密钥] [英] Insert '-' every 5 characters as users type [like a product key]
问题描述
可能重复:
使用jQuery插件自动格式化结构化数据(电话,日期)(或者使用那个vanilla JavaScript失败)
将特定字符后的空格插入javascript字符串
我正在尝试编写一个处理产品密钥的脚本,就像你在软件背面看到的那样和/或游戏。
I am trying to write a script that handles product keys like the ones you see on the back of software and games.
我希望当用户输入他们的密钥代码时,每5个字符插入' - '5个字符。 EX( ABCDE-FGHIJ-KLMNO-PQRST-UVWXY
)。所以当用户输入 ABCDE
时,只要' E
'被输入' - 通过jQuery或JavaScript后立即插入
'。
I would like so when the user is inputing their key code the '-' are inserted every 5 characters for 5 sets of characters. Ex(ABCDE-FGHIJ-KLMNO-PQRST-UVWXY
). So when the user enters ABCDE
as soon as the 'E
' is enetered a '-
' is inserted immeditly after via jQuery or JavaScript.
在此先感谢。
如果您有任何疑问或我不清楚,请评论:)
Thanks In Advance. Comment if you have any questions or if I was unclear :)
表格:
<form method="post" action="process.php">
<p>Key: <input name="key" id="key" size="40"></p>
<p><input type="submit"></p>
</form>
推荐答案
你可以使用 http://digitalbush.com/projects/masked-input-plugin/
jQuery(function($){
$("#key").mask("aaaaa-aaaaa-aaaaa-aaaaa-aaaaa");
});
这篇关于用户输入时每5个字符插入' - '[如产品密钥]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!