Regular Expression for single quote etc..

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

Hello

I'm new to Regular Expressions..

When the user types in a text box, I want the user to type only A-Z,
a-z, 0-9, comma, dash, period, single and double quotes.

How do I build such an expression.
Thanks
Sue..
 
Sue,

Sub TextBox1_Keypress(By Val sender as Object, _
ByVal e as KeyPressEventArgs) Handles TextBox1.KeyPress

Dim c as Char
c=e.KeyChar
If Not Char.IsLetterOrDigit(c) And Not c="." And Not c="-" _
Or Char.IsControl(c) Then
'Also look at Is Separator
e.Handled = True

End If

End Sub

Doug
 
Sue said:
Hello

I'm new to Regular Expressions..

When the user types in a text box, I want the user to type only A-Z,
a-z, 0-9, comma, dash, period, single and double quotes.

How do I build such an expression.
Thanks
Sue..

I'd rather see you doing this in a "Handles TextBox1.KeyPress" manner using
Char.IsLetterOrDigit(e.KeyChar) for a-zA-Z0-9 and Char.IsPunctuation for the
others (although you will have to refine this last a bit)

to do this with a RegEx, you would do something like this (untested)
[\w"-,'\.]+
 
Thanks for the reply..but the text box is a (.net) text box not a
regular text box, which has the keypress event...in such cases how do I
deal with it..

stand__sure said:
Sue said:
Hello

I'm new to Regular Expressions..

When the user types in a text box, I want the user to type only A-Z,
a-z, 0-9, comma, dash, period, single and double quotes.

How do I build such an expression.
Thanks
Sue..

I'd rather see you doing this in a "Handles TextBox1.KeyPress" manner using
Char.IsLetterOrDigit(e.KeyChar) for a-zA-Z0-9 and Char.IsPunctuation for the
others (although you will have to refine this last a bit)

to do this with a RegEx, you would do something like this (untested)
[\w"-,'\.]+
 
Sue said:
Thanks for the reply..but the text box is a (.net) text box not a
regular text box, which has the keypress event...in such cases how do I
deal with it..

I'm not clear on what you mean... are you referring to a textbox on a web
form?
 

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