问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/7833257/input-type-number-new-validation-removes-leading-zeros-and-formats-number-in-s