Regular Expression

jackdarippa
09-07-2009, 05:13 AM
Hello all,

I have a problem involving regular expression, i come from a web background and it seems alot easier to use regular expression in those languages. However, what im trying to do is validate a text field. The constraints are: only a-z, both upper and lower case and the value -. (as it can be a dash). Other characters such as ,.&, 123...9 are not allowed. Can anyone help with this.

sample code i am sort of using is: regEx.Pattern = "[a-zA-Z]$"

Can anyone shed some light on this.

Jac

kassyopeia
09-07-2009, 05:55 AM
Hi Jac,

I can't tell from your post which step you're having trouble with.

First, you need to reference the RegExp library: Tools->References->"Microsoft VBScript Regular Expressions".
Then, to validate a string, you can use code along these lines:

Dim re As RegExp: Set re = New RegExp
re.Pattern = "the pattern"
If re.Test("the string") Then '...

Finally, the correct pattern for what you are describing should be
^[a-zA-Z\-]*$
start-anchor, several lower or upper case characters or dashes, end anchor.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum