html5 input type number with regex pattern in mobile

后端 未结 5 1548
后悔当初
后悔当初 2020-12-08 13:35

I\'m trying to get regex pattern in input type number to show only numbers and dots. I tried something like this.



        
5条回答
  •  青春惊慌失措
    2020-12-08 14:26

    Not every input type and attribute is supported in all browsers. In general, most modern browsers from IE10+ include basics such as email and number.

    The browser will revert to a standard text input when a specific type and ignore attributes when those values are not supported.

    enter image description here enter image description here

    So you should use a good regular expression pattern.

    for example

    
    
    • 1234567899
    • 123 456 7899
    • 123-456-7899
    • 123.456.7899

    supported

    Browser support for 'tel' type

    • Android (yes)
    • iOS (yes)
    • IE (yes)
    • Mobile (yes)
    • Opera (yes)
    • Mobile (yes)
    • Opera (yes)
    • Classic (yes)
    • Opera Mini (no)
    • Firefox (yes)
    • Mobile (yes)
    • Chrome for Android (yes)

    (Sources: caniuse.com, DeviceAtlas, mobilehtml5.org)

    Browser support for pattern attribute

    But the pattern attribute is supported in Internet Explorer 10, Firefox, Opera, and Chrome. And is not supported in Internet Explorer 9 and earlier versions, or in Safari.

提交回复
热议问题