Parsley.js - Validate optional input for only numbers

后端 未结 1 2071
既然无缘
既然无缘 2021-02-20 03:30

I have a form that has one optional input and 3 required input fields. For the optional input I have the below markup:



        
相关标签:
1条回答
  • 2021-02-20 04:23

    You can use data-parsley-type="digits". Notice the use of type="text" instead of number.

    This works if you only want to allow digits (not floats).

    <input type="text" placeholder="0" min="0" max="20000" step="100" 
        data-parsley-validation-threshold="1" data-parsley-trigger="keyup" 
        data-parsley-type="digits" />
    

    If you want floats, you can use data-parsley-type='number':

    <input type="text" placeholder="0" min="0" max="20000" step="100" 
        data-parsley-validation-threshold="1" data-parsley-trigger="keyup" 
        data-parsley-type="number" />
    
    0 讨论(0)
提交回复
热议问题