Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - Useful FlatEdit pattern examples
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Useful FlatEdit pattern examples

 Post Reply Post Reply
Author
Message
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Topic: Useful FlatEdit pattern examples
    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.
Back to Top
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 11:19am
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
Back to Top
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 12:51pm
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.
Back to Top
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 4:12pm
Another one maching 0.01 to 1

^1|(0\.(0?[1-9]{1}|[1-9]{1}\d?))$
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 5:05pm
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



^((0*)1(\.{0,1})(0*)|0*|(0*)\.(\d{0,2}(0*)))$


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

Back to Top
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 5:20pm
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

Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 5:35pm
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:


Option Explicit

Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Const LOCALE_SDECIMAL = &HE         '  decimal separator

Private Function DecimalCharacter() As String
   Static s_Char As String
   Dim l_Len As Long
   Dim l_Locale As Long
  
   If LenB(s_Char) = 0 Then
      l_Locale = GetSystemDefaultLCID()
      l_Len = GetLocaleInfo(l_Locale, LOCALE_SDECIMAL, s_Char, Len(s_Char))
      If l_Len <> 0 Then
         s_Char = String$(l_Len, 0)
     
         GetLocaleInfo l_Locale, LOCALE_SDECIMAL, s_Char, Len(s_Char)
     
      End If
      s_Char = Left$(s_Char, InStr(1, s_Char, vbNullChar) - 1)
   End If

   DecimalCharacter = s_Char
End Function

Private Sub Form_Load()
   Me.FlatEdit1.Pattern = "^((0*)1(\" & DecimalCharacter & "{0,1})(0*)|0*|(0*)\" & DecimalCharacter & "(\d{0,2}(0*)))$"
End Sub


Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
JSram View Drop Down
Groupie
Groupie


Joined: 22 October 2004
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote JSram Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 6:28pm
yes good points and nice snippet.

1.00 to 360


^([1-2]{1}\d{0,2}(\.[0-9]{1,2}|)|(3{1}([0-5]{0,1}\d{0,1}(\.[0-9]{1,2}|)|6{1}0{1})|[4-9]{1}\d?(\.[0-9]{1,2}|)))$


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
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 27 October 2008 at 6:55pm
Nice! Here's my attempt, just to demonstrate a different approach. Not sure which one would be considered better.


^(([1-9]{0,1}[1-9]|1\d{0,2}|2\d{0,2}|3[0-5]{0,1}\d{0,1})(\.\d{1,2}|)|360)$


Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 28 October 2008 at 11:39pm
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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.