A
André Freitas
All fields in my project are validated with regular expressions. I have put
this regular expressions inside a certain function, like below:
Public Shared Function ValidateText(ByRef LabelName as String, ByVal Text As
String, ByVal Pattern As String) As Boolean
Dim vStringDictionary As StringDictionary
vStringDictionary = New StringDictionary
vStringDictionary.Add("UsernameP", "^[a-zA-Z0-9]{6,20}$")
vStringDictionary.Add("UsernameE", "Nome de usuário inválido.")
vStringDictionary.Add("PasswordP", "^[a-zA-Z0-9]{6,20}$")
vStringDictionary.Add("PasswordE", "Senha inválida.")
[...]
I do call the function passing the label where the message will apear, in
case of false, the text to validate, and the pattern name.
Using:
vStringDictionary(Pattern & "P") i do get the pattern, and
vStringDictionary(Pattern & "E") i do get the error message to return to the
label in case of false.
The problem is: always when i call this function im declaring the dictionary
again, and it sounds a waste. Anyone see a best logic for this?
Thx
this regular expressions inside a certain function, like below:
Public Shared Function ValidateText(ByRef LabelName as String, ByVal Text As
String, ByVal Pattern As String) As Boolean
Dim vStringDictionary As StringDictionary
vStringDictionary = New StringDictionary
vStringDictionary.Add("UsernameP", "^[a-zA-Z0-9]{6,20}$")
vStringDictionary.Add("UsernameE", "Nome de usuário inválido.")
vStringDictionary.Add("PasswordP", "^[a-zA-Z0-9]{6,20}$")
vStringDictionary.Add("PasswordE", "Senha inválida.")
[...]
I do call the function passing the label where the message will apear, in
case of false, the text to validate, and the pattern name.
Using:
vStringDictionary(Pattern & "P") i do get the pattern, and
vStringDictionary(Pattern & "E") i do get the error message to return to the
label in case of false.
The problem is: always when i call this function im declaring the dictionary
again, and it sounds a waste. Anyone see a best logic for this?
Thx