Last active
June 29, 2021 05:39
-
-
Save heri16/6ae175a14f0b8363bbcb9bac68132d8a to your computer and use it in GitHub Desktop.
Yup validate input for too many decimals to prevent ethers.js BigNumber / BigInt underflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let decimals = 4; | |
const regexpDecimals = new RegExp(`^\\d*\\.{0,1}\\d{0,${decimals}}$`); | |
const SignupSchema = Yup.object().shape({ | |
decimal: Yup.number().test( | |
'is-decimal', | |
'too many decimals', | |
value => (value + "").match(regexpDecimals), | |
), | |
}); | |
// Test cases | |
"424324.123456".match(new RegExp(`^\\d*\\.{0,1}\\d{0,6}$`)); | |
"424324".match(new RegExp(`^\\d*\\.{0,1}\\d{0,6}$`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment