[Gambas-user] IsDate(string) - how good is it?
Gianluigi
bagonergi at gmail.com
Thu Jan 6 16:17:50 CET 2022
About RegExp, you could do something like this :
(always to the puttanesca :-P)
[code]
Private hGrid As GridView
Public Sub Form_Open()
Dim hPan As HBox
Dim hButton As Button
Dim hDate As Date
Component.Load("gb.pcre")
hGrid = New GridView(Me) As "GridView1"
With Me
.H = 512
.W = 512
.Arrangement = Arrange.Vertical
.Margin = True
End With
With hGrid
.Expand = True
.Header = GridView.Horizontal
.Rows.Count = 4
.Columns.Count = 1
.Columns[0].Title = "DATE"
End With
hDate = Date(Now)
hGrid[0, 0].text = Format(hDate, "dd/mm/yyyy")
hGrid[1, 0].text = "6/Jan/2022"
hGrid[2, 0].text = "06/September/2021"
hGrid[3, 0].text = "Goofy"
With hPan = New HBox(Me)
.h = 40
End With
With hButton = New Button(hPan) As "Button1"
.AutoResize = True
.Text = "CLICK HERE"
End With
End
Public Sub Button1_Click()
Print IsAProbableDate(hGrid[0, 0].Text)
Print IsAProbableDate(hGrid[1, 0].Text)
Print IsAProbableDate(hGrid[2, 0].Text)
Print IsAProbableDate(hGrid[3, 0].Text)
End
Private Sub IsAProbableDate(value As String) As Boolean
If RegExp.Match(value, "([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})") Then
Return True
Else If RegExp.Match(value,
"(([0-9]{1,2}))/([a-zA-Z]{3,10})/([0-9]{2,4})") Then
Return True
Else
Return False
Endif
End
[code]
Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220106/2317e73e/attachment.htm>
More information about the User
mailing list