Regular Expression required

  • Thread starter Thread starter Sathyaish
  • Start date Start date
S

Sathyaish

RegEx heros,

I want to validate a certain field such that it shouldn't contain the
percentage character (%) or the asterisk character symbol (*). The
specification is that:

(1) The field must not contain the percentage symbol; AND
(2) The field must not contain the asterisk symbol.

It should contain neither of them. Can you please help me with the
RegEx for this?
 
Sathyaish,

Try something like:

Private Sub MyTextBox_KeyPress(ByVal sender As Object, _

ByVal e As System.Windows.Forms.KeyPressEventArgs) _

Handles MyTextBox.KeyPress

e.Handled = ChkEntry(e.KeyChar)

End Sub

Private Function ChkEntry(ByVal c As Char) As Boolean

Return c = "%" Or c = "%"

End Function

Doug
 
Hi,

You can use the regex ismatch method to tell if the character is
the string.

Dim rMatch As New System.Text.RegularExpressions.Regex("[%*]")
Trace.WriteLine(rMatch.IsMatch("There is a 10% drop in sales"))
Trace.WriteLine(rMatch.IsMatch("10 * 12 equals 120"))
Trace.WriteLine(rMatch.IsMatch("There is a 10 percent drop in sales"))


Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top