vbmark,
What I want is to only allow the user to have:
ONE minus sign *OR* ONE plus sign
Doh! changing the requirements on us. Typical User!
What is it specifically you want?
If you want 2 "-", 2 "+" or "+" & "-"
You can simplify it to:
Const pattern As String = "[\-\+].*[\-\+]"
If rx.Matches(thisTextBox.Text).Count > 1 Then
Wouldn't you want > 0? as you don't want any matches to be found.
I would probably simply use:
If Not rx.IsMatch(thisTextBox.Text) Then
Which says I don't want any matches..
Dim rx As New Regex("\-|\+") and
Dim rx As New Regex("[\-\+]")
Will match a "+" or a "-".
Again review the links I gave earlier as they explain HOW regular
expressions work. The two utilities I gave show HOW regular expressions
work. For example, enter "[\-\+].*[\-\+]" or "\-.*\-|\+.*\+|\-.*\+|\+.*\-"
in the regular expression tab of Expresso, then select the Analyzer tab in
Expresso, it will explain to you what the expression is doing.
I guessing that you really want to ensure that the string has a single "+"
or a single "-". You could use "[\-\+]" and check for number of matches...
Or possibly this one "^[^\-\+]*[\-\+][^\-\+]*$" and IsMatch.
Hope this helps
Jay