R
Reactiflux

✅ – ✅ – dmikester1 – 15-15 Jul 27

✅ – ✅ – dmikester1 – 15-15 Jul 27

Ddmikester17/27/2023
Hoping there are some regex gurus in here. I have an input where I simply need to allow numbers with a possible decimal. I did a lot of googling and stack overflowing. I found this regex: const re = /^\d+(\.\d{1,2})?$/; so my entire function looks like this:
const changePercent = (val) => {
console.log({ val });
const re = /^\d+(\.\d{1,2})?$/;
if (val === '' || re.test(val)) {
setPercentOfBatch(val);
}
};
const changePercent = (val) => {
console.log({ val });
const re = /^\d+(\.\d{1,2})?$/;
if (val === '' || re.test(val)) {
setPercentOfBatch(val);
}
};
I learned that i can paste in an entire number with a decimal just fine using that. But I cannot type the characters one by one. I assume that is because 12. does not match the regex. That makes sense, thank you.
UUUnknown User7/29/2023
4 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

✅ – ✅ – dmikester1 – 15-15 Jul 27

Join Server