简体   繁体   中英

Mask number input for text field and default to iPad number input?

Background

  • I have a form with a field that users will enter.
  • The input of the field is all numeric.
  • However, the result of the field will be masked to a text input
    • eg a user typing "9999999" will see "9999-999"
  • The field will ultimately be submitted as text.

I think the solution is to:

  • Use a plugin such as jQuery Mask to do input masking
  • Use the input type of "number" so that the iPad's keypad will default to a number

Problem

  • If I use the "number" input type, the masking won't work because it inserts a dash in a field reserved only for numbers.
  • If I use the masking with a text field, the iPad's keypad doesn't default to a number.

I used the code below:

$(document).ready(function() {
 var isiPad = navigator.userAgent.match(/iPad/i) != null;
 if (!isiPad){
  $("#id").mask("99999-999");
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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