Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct input type for IP Address

Tags:

html

What is the best practice for an input field that takes an IP-Address?

ie: Numbers and dots.

I've initially chosen type='number', However, I noticed that as soon as I type a second dot . followed by the next number, my submit button gets disabled.

ex: 123.124.4 (boom! button disabled)

Is the above due to a decimal consideration when it comes to type=number ?

<input type="number" class="input-box" placeholder="xxx.xxx.xxx.xx" autocomplete="off" />

Is there a way out of this without going with <input type='text'/> ?

like image 438
Null isTrue Avatar asked Mar 15 '18 18:03

Null isTrue


1 Answers

In HTML, you can verify input values with a pattern. This way, you can make something with a regular expression as following :

<input required pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$">
like image 53
kevinniel Avatar answered Oct 05 '22 06:10

kevinniel