I needed to use a regular expression to validate the shipping code that
was/is scanned by my application.
I use a windows (winform) application in Vb.net. I did it by creating
a function to handle the validation, and return true or false depending
on the value it received (which is just input from a scanner).
Make sure to import system.text.regularexpressions
Private Function ValidWaybill(ByRef strWaybill As String) As Boolean
If Regex.IsMatch(strWaybill, "^([A-Z]{2})([
]{1})([0-9]{4})([ ]{1})([0-9]{4})([ ]{1})([0-9]{1})([A-Z]{2})$") = True
Then
ValidWaybill = True
Else
ValidWaybill = False
End If
End Function
This works for me, at least it seems to.
The format of the value I need to validate is like this:
"AA 0000 0000 0AA"
So I made an expression that looks for two capital letters, followed by
a space. Next is two sets of 4 digit numbers, followed by spaces.
Last is one number, followed by two capital letters.
In my production code, the expression is stored in an XML file, and
this function reads it when it runs. This way, if I made a mistake, I
can fix it without re-compiling.
Hope this is usefull for someone!
Ciao.
Idletask