HTML5 Input type number removes leading zero on IOS

Input type number is a new attribute for input field in HTML5. In HTML5, you can have a Input type number field as a spinner which have up and down arrows at the right of the text box. This will help to increase or decrease the number value. When we use type=”number”, we can also use patterns for the values. Numeric input fields can take additional attributes “min” and “step”, which constrain the range of values allowed in your input. The “min” attribute is fairly obvious: it’s the minimum value your number can be. The “step” attribute is less intuitive: by playing with different values, you would most likely work out that it controls the increase/decrease when clicking the up/down buttons on the field. If you input the number 1 and click the up arrow, it will increase to 2.

Input type number issue on iOS

Input type number on Devices

When we use Input type number, on focus of the input field, numeric keypad will be opened on devices. If we use type=”text” normal character keybord opens and for entering numbers, we have to select number keypad. So, it is better to use input type=”number” for opening numeric keypad on focus of the input field.

Is there any issue on devices when we use Input type number?

HTML5 Input type number removes leading zero on IOS. But works fine on android devices. For example, when we use , Input type=number, and the user enter a value like ‘0001234’, then the input field removes ‘000’ and shows only 1234.

What is the solution for HTML5 Input type number removes leading zero on IOS?

Is there any solution for HTML5 Input type number removes leading zero on IOS? Can we use pattern attribute for fixing Input type number issue on iOS? Or will it create any other problems?

<input pattern="[0-9]*" type="text" />

Here one thing we have to notice that, when we click on the input type number field, numeric keypad should be opened. So that we can enter only numbers. But when we use the pattern with the type=”text”, the problem is that, on focus of the input, character keypad is opened instead of numeric keypad. Then user has to select numeric keypad for entering number.

How to Solve the Input Type Number issue on iOS?

The following can be a possible solution for fixing HTML5 Input type number removes leading zero on IOS issue.

<input pattern="[0-9]*" type="tel" />

Input type=”tel” accepts numbers. Here we are using a combination of both ‘tel’ and pattern. So that, on focus numeric keypad is opened and input field displays the complete number.

Is it bad to use input type=”tel” for numeric?

Would it be bad practice to use the tel input type for fields like credit card numbers to have the keypad popped on IOS devices?

Leave a Reply

Your email address will not be published. Required fields are marked *