pattern for input type=“text” with min and max number

前端 未结 3 1564
猫巷女王i
猫巷女王i 2020-12-18 04:07

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?

相关标签:
3条回答
  • 2020-12-18 04:47

    You can use the predefined min and max attribute for input type="number" as follows,

    <input type="number" min=0 max=10>
    <input type="submit">
        
    

    Here is an example

    The error for incorrect input will be displayed when you try to submit the form

    0 讨论(0)
  • 2020-12-18 04:51

    Let me know if this works :)

      <input type="number">
    

    HTML Version above!

    0 讨论(0)
  • 2020-12-18 05:03

    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]?))
    
    0 讨论(0)
提交回复
热议问题