drom / resch

:herb: React JSON Schema Form
https://beta.observablehq.com/@drom/resch-reactive-schema
MIT License
9 stars 2 forks source link

patterns for scientific application #36

Open danziamo opened 6 years ago

danziamo commented 6 years ago

regex for frequency

const re = /^(\d?\.?\d+(?:e\d)?){1}\s?([kKmMG]?(?:Hz)?)?$/

2.34 MHz should match 1.56e4 Hz should match 55 should match .44Hz should match 144 MHz should match 0.24 MHz should match 44 z not match 144t not match

piranna commented 6 years ago

The pattern is bad, {1} is superfluous and you are making the unit optional, so 1m would match.

danziamo commented 6 years ago

@piranna. Thank you. It really doesn't work. Any other working options?

danziamo commented 6 years ago
const re = /^([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?) ?([KkMm]?[Hh][Zz])?$/