Good afternoon! Here's our prompt for today.
Valid Numeric String
You are working as a software engineer at a company that develops a financial trading platform. Your team is working on a new feature that allows users to enter numeric strings into a text field and have them parsed and converted into numbers.
One of the requirements for this feature is that the numeric strings must be valid. A valid numeric string must consist of:
- A sign character (either
+
or-
). - One or more digits.
- A decimal point
.
followed by one or more digits. - An
e
orE
followed by an integer.
For example, all the following are valid numeric strings:
1"+"
2"-"
3"123"
4"-123.456"
5"1e10"
6"-90E3"
while the following are not valid numeric strings:
1"abc"
2"1a"
3"1e"
4"e3"
5"99e2.5"
You need to write a function that can be used to determine if a given string is a valid numeric string.

Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
// Function where students will fill out the logic
function validNumericString(s) {
// fill this in
return;
}
​
// Test cases to validate the function
function runTests() {
// Test case 1
const result1 = validNumericString("10.34");
if (result1 === true) {
console.log("Test case 1 passed");
} else {
console.log("Test case 1 failed");
}
​
// Test case 2
const result2 = validNumericString("10.34e10");
if (result2 === true) {
console.log("Test case 2 passed");
} else {
console.log("Test case 2 failed");
}
​
// Test case 3
const result3 = validNumericString("10.34.45");
if (result3 === false) {
console.log("Test case 3 passed");
} else {
Here's a video of us explaining the solution.
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.
Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.