Gambas France BETA


Pas de compte ? Incription

ExpressRegul

À propos de ce code

Juste un petit test sur les expressions régulières.

Code source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
' Gambas class file

PUBLIC CONST all AS STRING = "^.*$" 'tout est autorisé
PUBLIC CONST path AS STRING = "^[a-zA-Z0-9_.+-@:&/]*$" 'saisie d'un chemin
PUBLIC CONST url AS STRING = "^[a-zA-Z0-9_.+-@:&!*'();:@=+$,/?#\\[\\]%]*$" 'saisie d'une url ... a revoir
PUBLIC CONST code AS STRING = "^[a-zA-Z0-9]*$" 'saisie d'un code tel que supporté par Laurux
PUBLIC CONST compte AS STRING = "^[0-9]*$" 'saisie d'un compte à la main
PUBLIC CONST num AS STRING = "^-?[0-9]*[,.]?[0-9]*$" 'saisie d'un numérique avec ,
PUBLIC CONST numVirgul2 AS STRING = "^-?[0-9]*[,.]?[0-9]{0,2}$" 'valeur numérique avec deux décimales
PUBLIC CONST numVirgul3 AS STRING = "^-?[0-9]*[,.]?[0-9]{0,3}$" 'valeur numérique avec deux décimales
PUBLIC CONST chaine AS STRING = "^[^ % ^_]*$" 'saisie d'une chaîne en excluant les caractères spéciaux de recherche BD
PUBLIC CONST courriel AS STRING = "^[A-Z0-9._%+-]+@[A-Z0-9._%-]+.[A-Z]{2,63}$" 'saisie d'une adresse courriel
PUBLIC CONST dts AS STRING = "^[0-9]{0,2}[./-]?[0-9]{0,2}[./-]?[0-9]{0,4}$" 'Date
PUBLIC CONST dtst AS STRING = "^[0-9]{0,2}[./-]?[0-9]{0,2}[./-]?[0-9]{0,4}[ ]?[0-9]{0,2}[:]?[0-9]{0,2}$" 'Date + time
PUBLIC CONST tel AS STRING = "^(0|'\'+33)[1-9]( *[0-9]{2}){4}$"
PUBLIC CONST https AS STRING = "^https?://[a-zA-Z0-9'\'.-]+'\'.[a-zA-Z]{2,4}(/'\'S*)?$"

PUBLIC Liste AS NEW String[]
PUBLIC ListeB AS NEW String[]

PUBLIC $reg AS STRING

PUBLIC $regex AS NEW RegExp

PUBLIC bEstNum AS BOOLEAN
PUBLIC bEstMail AS BOOLEAN

PUBLIC SUB _new()

DIM sCste AS STRING
DIM i AS INTEGER

'si vous ajoutez une constante ajoutez son nom, à Liste et votre commentaire, à ListeB. À LA MÊME POSITION.
'Se aggiungi una costante aggiungi il suo nome, per elenco e il tuo commento, a ListB. Nella stessa posizione.

Liste = [all, path, url, code, compte, num, numVirgul2, numVirgul3, chaine, courriel, dts, dtst, tel, https]
ListeB = [("Tout est possible"), ("Chemin de Dossier"), ("URL"), ("Code"), ("Valeur de Compte"), ("Valeur Numérique", ("Valeur Numérique à deux décimales"), ("Valeur Numérique à trois décimales"), ("Chaîne de Recherche dans Base de Données"), ("Adresse courriel"), ("Date sans le Temps"), ("Date avec le Temps"), ("Numéro de téléphone (France)"), ("Lien internet https")]

i = 0
FOR EACH sCste IN Liste
ListView1.Add(CStr(i), sCste)
INC i
NEXT

END

PUBLIC SUB ListView1_Select()

$reg = ListView1.Current.Text
$Regex.Compile($reg, $regex.Caseless)
TextBox1.Text = $reg
TextBox2.Text = ListeB[CInt(ListView1.Key)] & ", cle = " & ListView1.Key

END

PUBLIC SUB Form_Close()

Settings.Write(ME)

END

PUBLIC SUB Form_Open()

Settings.Read(ME)
ListView1.Key = "0"
ME.Text = "Expressions Régulières ~ " Application.Title & " ~ " & Application.Version

END

PUBLIC SUB butb_Click()

Desktop.Open("https://regex101.com/")

END

'-------------------- Début évènement keypress ----------------------------
PUBLIC SUB Form_KeyPress()

IF Key.Code = Key.Esc THEN ME.Close

END

PUBLIC SUB tbEmail_KeyPress()

IF Key.Code = Key.Enter OR Key.Code = Key.Return THEN
IF tbEmail.Text = "" THEN RETURN
IF NOT $Regex.Match(tbEmail.Text, $reg, $Regex.Caseless) THEN
Message.Info(("Remplissez correctement le champs eMail"))
tbEmail.Text = ""
tbEmail.SetFocus
' Stop Event
ELSE
Message("Adresse Mail Valide !")
tbEmail.Text = ""
tbEmail.SetFocus
ENDIF
ENDIF

CATCH
Message(Error.Text, Error.Code)

END

PUBLIC SUB butb_KeyPress()

IF Key.Code = Key.Enter OR Key.Code = Key.Return THEN
IF butb.Text = "" THEN RETURN
IF NOT $Regex.Match(butb.Text, $reg, $Regex.Caseless) THEN
Message.Info(("Le champs saisi ne correspond pas \n à l'expression régulère suivante :\n " TextBox2.Text)
butb.Text = ""
butb.SetFocus
ELSE
Message(("Expression valide pour \n") & TextBox2.Text & " !")
butb.Text = ""
butb.SetFocus
ENDIF
ENDIF
CATCH
Message(Error.Text, Error.Code)

END

PUBLIC SUB tb2_KeyPress()

IF IsNumber(tb2.Text) AND $regex.Pattern <> tel THEN bEstNum = TRUE
IF $regex.Pattern = courriel THEN bEstMail = TRUE

IF Key.Code = Key.Enter OR Key.Code = Key.Return THEN
IF tb2.Text = "" THEN RETURN
IF TextBox1.Text = "" THEN RETURN
IF NOT $Regex.Match(tb2.Text, $reg, $Regex.Caseless) THEN
Message.Info(("Le champs saisi ne correspond pas \n à l'expression régulère suivante :\n " TextBox1.Text)
tb2.Text = ""
tb2.SetFocus
ELSE
Message(("Expression valide pour \n") & TextBox1.Text & " !")
tb2.Text = ""
tb2.SetFocus
ENDIF

bEstNum = FALSE
bEstMail = FALSE

ENDIF
CATCH
Message(Error.Text, Error.Code)

END
'-------------------- Fin évènement keypress ----------------------------

'-------------------- Début évènement change --------------------------

PUBLIC SUB butb_Change()

IF butb.Text THEN $Regex.Exec(butb.Text)

IF ListView1.Key = 5 OR ListView1.Key = 6 OR ListView1.Key = 7 OR ListView1.Key = 4 OR ListView1.Key = 10 OR ListView1.Key = 11 THEN 'num
butb.Editor.Text = $Regex.Text
IF butb.Editor.Text MATCH "." THEN butb.Editor.Text = Replace(butb.Editor.Text, ".", ",")
ENDIF

CATCH
Message(Error.Text, Error.Code)

END

PUBLIC SUB tb2_Change()

IF tb2.Text THEN $Regex.Exec(tb2.Text)

IF bEstNum = TRUE THEN
tb2.Text = $Regex.Text
IF tb2.Text MATCH "." THEN tb2.Text = Replace(tb2.Text, ".", ",")
ENDIF

CATCH
Message(Error.Text, Error.Code)

END

'-------------------- Fin évènement change --------------------------

'-------------------- Début évènement enter -------------------------

PUBLIC SUB tbEmail_Enter()

$reg = "^[A-Z0-9._%+-]+@[A-Z0-9._%-]+.[A-Z]{2,63}$"
$Regex.Compile($reg, $Regex.Caseless)

END

PUBLIC SUB tb2_Enter()

IF TextBox1.Text = "" THEN RETURN
$reg = TextBox1.Text
$Regex.Compile($reg, $Regex.Caseless)

END

PUBLIC SUB butb_Enter()

IF IsNull(ListView1.Key) THEN RETURN
$reg = ListView1.Current.Text
$Regex.Compile($reg, $Regex.Caseless)

END
'-------------------- Fin évènement enter -------------------------

Commentaires

Commentaire de valaquarus, Le 27/6/2022 à 09:57:12
Traduit en italien pour Vuott
Commentaire de valaquarus, Le 27/6/2022 à 10:01:27
Pour nos amis italien du site : https://www.gambas-it.org/smf/