I'm trying to get a validation of a text box to where if the information is not letters then it will display a error message. I know how to get the error message, but I dont dont know how to do a validation with letters. I know how to do it with number but not letters. Please help. Thanks.
Help with validation problem
Collapse
X
-
Hi dwd3773 -Originally posted by dwd3773I'm trying to get a validation of a text box to where if the information is not letters then it will display a error message. I know how to get the error message, but I dont dont know how to do a validation with letters. I know how to do it with number but not letters. Please help. Thanks.
You may try these codes below
Godspeed!Code:Const strAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Private Sub cmdValidate_Click() If InvalidTextboxInput = True Then MsgBox "Textbox contains invalid character.", vbExclamation Else MsgBox "Valid textbox content.", vbInformation End If End Sub Private Function InvalidTextboxInput() As Boolean For i = 1 To Len(TextBox1.Text) If InStr(strAlphabet, UCase(Mid(TextBox1.Text, i, 1))) < 1 Then InvalidTextboxInput = True Exit For End If Next i End Function -
Quick question - what version of VB are you using?Originally posted by dwd3773I'm trying to get a validation of a text box ...
Oh, and another question - have you considered using a masked edit control rather than a textbox? The masked edit control gives you more control over the format of the input.Comment
-
Fair enough.Originally posted by dwd3773No, I haven't thought of using one of those. I have strict guideline from my customer as to what they want, but I've never really validated letters only numbers. I 'm using Microsoft Visual Studio 2005.
You might as well go with the routine that fplesco provided. It looks as though it will work. One small change I would recommend, though. That is to have it accept the textbox (or just the text) as a parameter, so it's more widely applicable. Seems as though it would make a useful public function to add to your tool kit.Comment
-
Originally posted by Killer42Fair enough.
You might as well go with the routine that fplesco provided. It looks as though it will work. One small change I would recommend, though. That is to have it accept the textbox (or just the text) as a parameter, so it's more widely applicable. Seems as though it would make a useful public function to add to your tool kit.
[That is to have it accept the textbox (or just the text) as a parameter, so it's more widely applicable]
Good point Killer42. Thanks.Comment
-
I think it's a good general technique to try and write all one's routines so they're reusable. Though of course there are other considerations, such as performance.Originally posted by fplescoGood point Killer42. Thanks.
(And of course, being so disorganised, I can never find them again later, anyway. But my intentions are good.)Comment
Comment