2

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.

3
  • it is not semantically correct to use an input with a number type and requesting a non-number value. Commented Apr 13, 2015 at 10:28
  • then do u have anything with javascript? Commented Apr 13, 2015 at 10:36
  • 1
    I did not understand you were looking for to select a mobile virtual keyboard Commented Apr 13, 2015 at 11:09

2 Answers 2

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\/]*">
Sign up to request clarification or add additional context in comments.

2 Comments

It gives some symbols also..How can I restrict those and allow only forward slash?
In my opinion that is not possible, your phone has some default keyboards you can chose from through the html5 tag, thats it. I think if you want a more specific phonelayout thats only possible with a native app. (If it is possible)
0

You should change the input type to text:

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

See more information here.

1 Comment

It does not matter if you give text or not, it won't users submit junk, only what is allowed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.