Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pattern for input type="text" with min and max number

how to write pattern for input type="text" (it can't be number and the validation can't be with JS) that allow me to enter only numbers, min:1 and max:5000?

    <input type="text" name="someName" id="someId" required pattern=""/>
like image 786
artur47wien Avatar asked Jun 11 '15 16:06

artur47wien


People also ask

How do you set the maximum and minimum value of an input type text?

addEventListener('change', function(e) { var num = parseInt(this. value, 10), min = 0, max = 100; if (isNaN(num)) { this. value = ""; return; } this.

How do I limit text input to numbers?

To limit an HTML input box to accept numeric input, use the <input type="number">. With this, you will get a numeric input field. After limiting the input box to number, if a user enters text and press submit button, then the following can be seen “Please enter a number.”

How do you set min and max time in HTML?

Definition and Usage The min attribute specifies the minimum value (time) for a time field. Tip: Use the min attribute together with the max attribute to create a range of legal values. Tip: To set or return the value of the max attribute, use the max property.

How do you write an input tag pattern?

The pattern attribute specifies a regular expression that the <input> element's value is checked against on form submission. Note: The pattern attribute works with the following input types: text, date, search, url, tel, email, and password. Tip: Use the global title attribute to describe the pattern to help the user.


1 Answers

Here you go - not an input with type="number" and no JS:

<input type="text" name="someName" id="someId" required="required"
 pattern="(5000|([1-4][0-9][0-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9])|[1-9])"/>

The basic pattern is to match 5000 or 4-digit number or 3-digit number or 2-digit number or non-zero 1-digit number.

If you can accept 0, the pattern can be even simpler:

(5000|([1-4]?[0-9]?[0-9]?[0-9]?))
like image 102
light Avatar answered Oct 01 '22 15:10

light