Input type='number' new validation removes leading zeros and formats number in Safari for iPhone iOS5 and latest Safari for Mac
Asked Answered
B

1

8

The latest Safari for MacOS and the one that comes in iOS5 has some extra validation that causes problems if the text field is not a phone number.

Case: Input text field with type="numeric" attribute.

Problems: 1) Number gets formatted as a phone number. E.g. if I type '012345678' it gets formatted as '012 345 678'

2) Leading zeros are being removed. E.g. '01234567' gets formatted as '1234567'

I could just remove the type="numeric" attribute on my text field and probably the problem will disappear, but I would really like to use the numeric keypad for this text field instead of the normal keyboard on the iPhone.

Any ideas how to fix this?

Many thanks

Bryna answered 20/10, 2011 at 8:45 Comment(0)
B
8

I change type="number" to type="tel" and works fine. I did some quick testing and have not found any validation or auto-formatting of the text either.

Bryna answered 24/10, 2011 at 11:11 Comment(2)
You rock. Got to hold down CTRL-Z and undo a bunch of hacks thanks to your answer.Sully
but you can't use the period for decimals .Wardrobe

© 2022 - 2024 — McMap. All rights reserved.