Useful FlatEdit pattern examples |
Post Reply |
Author | |
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
Posted: 27 October 2008 at 11:01am |
I originally asked for help with a pattern in this threed as the docs just have one simple example. I finally figured it out and thought of keeping this treed instead as something of a collection of usefull patterns, so feel free to add your own.
|
|
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
|
This pattern allow for either an integer value from 1 to 13 OR same int value plus a decimal 1 or 2 digits raging from .00 to .99
^(1[0-3]?|\d)(\.[0-9]{1,2}|)$ alternative range 1 to 19 for integer part ^(1\d?|\d)(\.[0-9]{1,2}|)$ note: [0-9] can be replaced with \d, the former is more illustrative though |
|
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
|
Here is a patterns that matches -100 to 100, 0 inclusive
^((-|)((1(0{2}|\d?))|([2-9]\d{0,1}))|0{1})$ and same but 0 exclusive ^(-|)((1(0{2}|\d?))|([2-9]\d{0,1}))$ There might be a more effective way to do it, by someone smarter then me but as the docs literally lacks examples (except \d*) it might be usefull to someone. |
|
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
|
Another one maching 0.01 to 1
^1|(0\.(0?[1-9]{1}|[1-9]{1}\d?))$ |
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Thanks JSram...nice examples.
I modified your last one a bit to allow any number that would Val() from 0 to 1 with a maximum of 2 decimal places > 0, but any number of leading/trailing 0s. For example, some valid entries: 1 1. 1.0 1.00000000000000 0 0. 0.000000000 0.01 0.010000000 00000.000000 00001.00000 .001 Invalid: 0.001 1.001
This is useful for allowing copy & paste from formatted sources, but ensuring the underlying value of the entry is within a range of values. |
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
|
Yes that's a nice example too, keep them coming
One point regarding my integer/decimal sample is eighter enter integer soley, or add dot plus decimal part (and limit to 2 places), but not dot alone. I know it's cosmetic though but I don't like stored data like .75 or 2. as it tend to cause problem eventually somewhere down the road. I am really a novis o expressions though and just try to improve my skills, right now I try to figure out (>=1 AND <=360, integers optionally with 2 decimals - anyone take the challange |
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
I'm no Regex expert myself, but I will give your challenge a shot for the learning experience...
As for the cosmetic requirements, I can understand, I just thought I'd give an example that would allow any entry that evaluates to the same number. This allows you to store any entry in a database as a SINGLE/FLOAT datatype, and then restore the saved value to any format you like using the Format$ function (in case anyone else needs to do such a thing!). On another note, one thing I recommend is to use the Pattern property at runtime and substitute the \. portions with the user's locale decimal character (in some countries it would be , instead of .). Something like this should work:
|
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
JSram
Groupie Joined: 22 October 2004 Status: Offline Points: 42 |
Post Options
Thanks(0)
|
yes good points and nice snippet.
1.00 to 360
at least it's one way to do it, decimals allowed for 1-359 but not for 360 |
|
Product: Xtreme SuitePro (ActiveX) version 15.3.1
Platform: Windows 7 Ultimate (64bit) - SP1 Language: Visual Basic 6.0 SP6 |
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Nice! Here's my attempt, just to demonstrate a different approach. Not sure which one would be considered better.
|
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Hi JSram,
I just uploaded a demo to the VB6 samples board that you might be interested in. It is code that automatically generates the required regex pattern for a user-supplied range and number of decimal places. Should be useful in a variety of situations. Right now it only handles positive numbers, but that was enough to nearly drive me crazy :) There may be bugs, so beware of using it in production without extensive testing. https://forum.codejock.com/forum_posts.asp?TID=12556 |
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |