简体   繁体   English

jQuery输入掩码数字

[英]jquery input masked digits

I have input field form to enter credit card number and I want to enter first 4 and last 4 digits how can I do it? 我有输入字段表格来输入信用卡号,我想输入前4位和后4位数字,该怎么办?

For example: In image when I focus and fill input it must fill group 1 and group 2 characters 例如:在图像中,当我聚焦并填充输入时,它必须填充第1组和第2组字符

click see to demo 点击查看演示

在此处输入图片说明

My HTML 我的HTML

<input type="text" name="kredi_karti" id="kredi_karti" class="form-control kredi_karti">

jQuery code: jQuery代码:

$(document).on("focus",".kredi_karti",function(){
    $(this).mask("9999 9999 9999 9999",{placeholder:"XXXX XXXX XXXX XXXX"});
});

that's not so hard as you think, you can write a key down event function and store the key input in the variable and return the mask keycode to set in input, you also have to verify the key code if its delete or backspace you have to change the stored card number accordingly 这并不像您想象的那么难,您可以编写一个按键按下事件函数并将按键输入存储在变量中,并返回要在输入中设置的掩码按键代码,还必须验证按键代码是否必须删除或退格相应地更改存储的卡号

here is the code which allows only numbers .. you have to extend the functionality 这是只允许数字的代码..您必须扩展功能

Allow only numbers to be typed in a textbox 只允许在文本框中键入数字

Try this out to skip the second and third groups of numbers 尝试跳过第二和第三组数字

$(this).mask('0000.XXXX.XXXX.0000', {
  translation: {
    'X': {
      pattern: /X/,
      fallback: 'X'
    }
  },
  placeholder: "____.XXXX.XXXX.____"
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM