Number inputs only allow the e to occur between two digits. To match any number, you can use the character class [0-9]. This will match any digit between 0 and 9.
Add this character class before and after e in your pattern.
After playing around with regex I wasn’t able to find the logic of adding [0-9] in the pattern. For example
console.log(“1.23E+10”.replace(/e/i, “”))
would result in 1.23+10 and
console.log(“1.23E+10”.replace(/e+/i, “”))
would result in 1.2310
Using a real invalid number:
I guess the regex may be made better? But the numbers used in the project do not use + in front of the exponent, so that could be where your confusion is.
this patter could be made better with an optional ± in front of the exponent, you are right.
Question here, why are you using replace to test the regex? wouldn’t match be better?
are you asking what is the purpose of checking for a digit before and after the e?
Because this project wants to use this function to check for that.
(it isn’t to do any kind of replace. It is just to confirm that the letter e is sandwiched between two digits)
I guess the regex may be made better? But the numbers used in the project do not use + in front of the exponent, so that could be where your confusion is.
Many thanks for your reply! Looks like I missed there the escape, wasn’t intentional.
Question here, why are you using replace to test the regex? wouldn’t match be better?
Would sound strange, but I’m not that far in the curriculum. At this point I don’t know yet the functionality of “match”.^^
are you asking what is the purpose of checking for a digit before and after the e?
Yes and no. I just had the idea using it in replace function and play around to see what it does.
(it isn’t to do any kind of replace. It is just to confirm that the letter e is sandwiched between two digits)
Yes. But (maybe a silly question), is it technically possible to build a logical example using [0-9] in combination with the replace function which clearly demonstrates the use of it?
I was referring to the [0-9] pattern initially - but this is now sorted anyway. I kept playing around and researching, and was able to erase the question marks in my mind. Many many thanks again for your support!