React-number-format: Limit value.

Created on 12 Oct 2017  路  7Comments  路  Source: s-yadav/react-number-format

I can't limit value ????????
event on Keydown, onKeyup .... I not found.
example : min : 5 or Max: 10000

Most helpful comment

<NumberFormat isAllowed={(values) => {
    const { formattedValue, floatValue } = values;
    return formattedValue === "" || floatValue <= 10000;
}}/>

All 7 comments

Use isAllowed prop to validate input. Something like

<NumberFormat isAllowed={(values) => {
  const {floatValue} = values;
  return floatValue >= 5 &&  floatValue <= 10000;
}}/>

thanks you very so much!

If i want to do the max limit, ho w can i do that?
const {floatValue} = values;
return floatValue <= 10000;
}}/>

The above example is not working as i cant make empty input field or remain blank an input field, there is always one number is present in the input field.

Same issue here as mglrahul, how did this get resolved?

<NumberFormat isAllowed={(values) => {
    const { formattedValue, floatValue } = values;
    return formattedValue === "" || floatValue <= 10000;
}}/>

The solution provided didn't work for me, at least when I implemented them min value. I set a minimum value of 5 and the input would block me from inserting any value starting with 1, 2, 3 or 4. Even when my intention was inserting 10 or 12, I couldn't, because the first character is 1, and 1 is lower than 5. Here's my code:

 isAllowed={values => {
        const {formattedValue, floatValue} = values
        return formattedValue === '' || (floatValue <= 15 && floatValue >= 5)
      }}

Has anyone gone through this and found a solution?

The solution provided didn't work for me, at least when I implemented them min value. I set a minimum value of 5 and the input would block me from inserting any value starting with 1, 2, 3 or 4. Even when my intention was inserting 10 or 12, I couldn't, because the first character is 1, and 1 is lower than 5. Here's my code:

 isAllowed={values => {
        const {formattedValue, floatValue} = values
        return formattedValue === '' || (floatValue <= 15 && floatValue >= 5)
      }}

Has anyone gone through this and found a solution?

this works for me:

isAllowed={values => {
    const { formattedValue, floatValue } = values
    if (floatValue == null) {
        return formattedValue === ''
    } else {
        return (floatValue <= 15 && floatValue >= 5)
    }
}}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

osvaldokalvaitir picture osvaldokalvaitir  路  3Comments

ddmedeiros picture ddmedeiros  路  6Comments

fedulovivan picture fedulovivan  路  6Comments

erasmo-marin picture erasmo-marin  路  3Comments

rioarray picture rioarray  路  6Comments