Regular Expression

User 2185412 Photo


Registered User
44 posts

Does anyone know how to make an expression that will accept numbers less than a certain number?

Example [<150]
So it would except: 5, 25, 100, 149, ect.... but not 150, 155, 200, and so on.
User 187934 Photo


Senior Advisor
20,271 posts

Maybe.:)
/^[0-149]$/

Edit: That's not correct. Let me try something else. Sorry.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2185412 Photo


Registered User
44 posts

I know I can do this and list every number if I had to
/^((1)|(2)|(3)|(4)|.....................(147)|(148)|(149))$/
but i'm sure there is a much easier and faster way

User 2185412 Photo


Registered User
44 posts

I found a site http://www.regular-expressions.info/numericranges.html
Here it is
/^(0?[0-9]?[0-9]|1[0-3][0-9]|14[0-9])$/

Thanks Rolly
User 187934 Photo


Senior Advisor
20,271 posts

Thanks for figuring that out. It will be useful for other users looking to work with numbers in their forms.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2514104 Photo


Registered User
43 posts

I think there is a problem with the custom setting of your RE field. I have searched the web for currency formats and every one i put in the field generates an error.
Here is one example: ^(\$|)([1-9]\d{0,2}(\,\d{3})*|([1-9]\d*))(\.\d{2})?$ from regexlib.com.
User 2514104 Photo


Registered User
43 posts

The issue is that the CoffeeCup editor needs the RE string to be enclosed in forward slashes e.g. ^(\$|)([1-9]\d{0,2}(\,\d{3})*|([1-9]\d*))(\.\d{2})?$ will not work but /^(\$|)([1-9]\d{0,2}(\,\d{3})*|([1-9]\d*))(\.\d{2})?$/ works just fine.
User 271657 Photo


Ambassador
3,816 posts

Thanks for that info, imwa :D
I've wondered why sometimes they work and sometimes they don't.
I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
https://www.callendales.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.