0

I am trying to create a regular expression that can accept only number, decimal(upto 18 decimal places) and can accept exponential value(E-14) etc. Below is the expression I have used

for number and decimals

^-?[0-9]\\d*(\\.\\d{1,17})?$ 

Working fine for decimal and numbers, but do not accept exponent

EXAMPLE VALUES THAT DO NOT WORK:

2.22050858570371E-14
2.23879285E-143  

EXAMPLE VALUE THAT WORKS:

3456
0.1002323
453.45455

Regular Expression that accept Exponent value (E-e)

( ([0-9]+(\.[0-9]*)?) | (\.[0-9]+) )( (e|E)(\+|\-)[0-9](\.[0-9])? )?

EXAMPLE VALUES THAT DO NOT WORK:

2.22050858570371E-14
2.23879285E-143  

I tried searching the net, but didn't found anything useful that can help me in achieving the functionality. The typescript code idea doesn't accept it or I used a wrong regex.

Thanks,

Running Rabbit
  • 2,634
  • 15
  • 48
  • 69
  • E.g. https://regex101.com/r/TKPQjX/1 – Wiktor Stribiżew Jul 07 '22 at 11:00
  • 1
    How about [something like this (demo)](https://regex101.com/r/y0MJ9Y/1) – bobble bubble Jul 07 '22 at 11:04
  • Matching numbers with scientific notation is a solved issue, no need for a new thread. – Wiktor Stribiżew Jul 07 '22 at 11:40
  • @WiktorStribiżew: I tried the steps that is mentioned in the other thread.. it actually accepts number with words.. thats why I created a new thread as I already mentioned that i was not able to find the acceptable answer on the net.. – Running Rabbit Jul 07 '22 at 16:04
  • @RunningRabbit Yw, I already voted for reopening. Can't see it's a duplicate (many questions are somehow related to an older one)... There was some discussion and comments have been deleted. No worries however... – bobble bubble Jul 07 '22 at 16:12
  • The top comment is from the first accepted answer. The https://regex101.com/r/QxOYjo/1 is from https://stackoverflow.com/a/71163684/3832970. A lot of solutions already posted, no need for reopening. – Wiktor Stribiżew Jul 07 '22 at 16:18

0 Answers0