I'm trying to "validate" some input from a form on the backend but I kinda got stuck with the required regex. Basically, I want to get a number, no leading zeroes, with an optional decimal and an optional case insensitive thousands notation (1,000 = 1k, 1,000,000 = 1m, 1 billion = 1b ...) These should match/validate:
12.39 12.389k 99.1003b 40.1m
These should fail.
0.0 12.00b 1e3 2^5 0xFF 12.6z asdf
So far I've tried this:
^[1-9]\d*(?:\.\d+)?(?:[kmbt])?$
It works but I'm thinking maybe someone could solve this a bit more elegantly than I did.
12.00b99.1003band fail on12.00b?thousands notation, is that something you care about? There are no examples in your examples but your description mentions it. or40.1mis in your string but denotes40,100,000?