Restrict special characters

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



How do i restrict users from inserting special characters in a text box.

Right now I am restricting the users from entering a single quote ' in the
text box.
I check for these sepecial characters when they hit the save button on the
screen.

Currently I use the following code:
' Name should not contain a single quote.
If InStr(Trim(txtName.Text), "'") <> 0 Then
editTransaction = blnAllowExit
showMsg("Name Should not contain a single quote.Please correct
before
saving", MsgBoxStyle.Critical, strTitle)
txtName.Focus()
Exit Function
End If

How do I restrict the rest of the special characters except for - and _.
Please help...

Thanks a lot.
Hima..

.


Quantcast