Re: Restrict special characters
- From: "Rick Rothstein" <rick.newsNO.SPAM@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 3 Jan 2009 00:24:06 -0500
Of course, I don't consider one-line If..Then constructions to be *true* one-liners. For those of you expecting to see me post a *true* one-liner, who am I to disappoint you<g>...
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = -KeyAscii * (Not Chr$(KeyAscii) Like "*[!a-zA-Z0-9]*")
End Sub
--
Rick (MVP - Excel)
"Rick Rothstein" <rick.newsNO.SPAM@xxxxxxxxxxxxxxxxxx> wrote in message news:e0AkD5VbJHA.4900@xxxxxxxxxxxxxxxxxxxxxxx
It is often easier to define 'allowable' characters opposed to excluding
specific ones. See this as a common solution:
http://www.vb-helper.com/howto_allow_letters_numbers.html
The KeyPress event at that site has way too many lines of code for my taste. I would use this instead...
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr$(KeyAscii) Like "*[!a-zA-Z0-9]*" Then KeyAscii = 0
End Sub
--
Rick (MVP - Excel)
.
- Follow-Ups:
- Re: Restrict special characters
- From: Ralph
- Re: Restrict special characters
- References:
- Re: Restrict special characters
- From: Rick Rothstein
- Re: Restrict special characters
- Prev by Date: Re: Restrict special characters
- Next by Date: Re: Drag/Resize Samples
- Previous by thread: Re: Restrict special characters
- Next by thread: Re: Restrict special characters
- Index(es):
Relevant Pages
|