[RESOLVED] Help with regular expression
I need to test a string of text that needs to contain a certain type of char values. The known is allowing of a-z,A-Z,0-9. But the variable (which will be coming from a database field) will be the allowed symbols. The allowed symbols will look something like:
!@#$%^&*()
So using regex, how can I check a string of text to make sure it ONLY contains a-z,A-Z,0-9 AND the allowed symbols as shown above? Remember, the allowed symbols is dynamic at run time so I need to somehow be able to plug that in to the method at run time.
The following examples would be valid using the above symbol string:
Test1234%
Test1234
The following example would NOT be valid:
Test1234%_
Re: Help with regular expression
Code:
Dim pattern = "A-Za-z0-9"
pattern &= Regex.Escape("!@#$%^&*()")
pattern = "^[" & pattern & "]+$"
Dim exp As New Regex(pattern)
Debug.WriteLine(exp.IsMatch("Test1234%"))
Debug.WriteLine(exp.IsMatch("Test1234"))
Debug.WriteLine(exp.IsMatch("Test1234%_"))
Re: [RESOLVED] Help with regular expression