最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - html5 input type number with regex pattern - Stack Overflow

programmeradmin4浏览0评论

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

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

But getting only 0-9 number pad. How can I show 0-9 number pad as well as forward slash "/" in regex.

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

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

But getting only 0-9 number pad. How can I show 0-9 number pad as well as forward slash "/" in regex.

Share Improve this question asked Apr 13, 2015 at 10:25 UI_DevUI_Dev 3,42718 gold badges53 silver badges93 bronze badges 3
  • it is not semantically correct to use an input with a number type and requesting a non-number value. – Gaël Barbin Commented Apr 13, 2015 at 10:28
  • then do u have anything with javascript? – UI_Dev Commented Apr 13, 2015 at 10:36
  • 1 I did not understand you were looking for to select a mobile virtual keyboard – Gaël Barbin Commented Apr 13, 2015 at 11:09
Add a ment  | 

2 Answers 2

Reset to default 2

You could use input type "text" for only the validation purpose.

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

You can consider the "tel" input type, for a simpler keybord layout containing the slash on a mobile device

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

You should change the input type to text:

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

See more information here.

发布评论

评论列表(0)

  1. 暂无评论