@mihalymarcell86
Posted
Hello @mahadaamir35,
good job on the challenge!
The problem with the input validation occurs, because the parseFloat
function only returns NaN
, when the first non-whitespace character cannot be converted to a number, which doesn't exclude the possibility of trailing letters. You can either use RegExp, to check for a pattern, like /^\d+$/.test(enteredValue)
, or you could set the <input>
element to type='number'
which will automatically disallow the input of non-numeric characters (except +, - and .).
Hope, this helps!
Marked as helpful
@mahadaamir35
Posted
@mihalymarcell86 Hi Marchel,
Yeah I was having this issue while using parseFloat. The input element when set to number should make this problem easier for me.
Thanks for the feedback.