Hello,
I currently have a userform with a textbox that limits the user input to accept only alphanumeric. I had found that code in an older thread on this board here.
The code works great but now I've decided that the user should also be allowed to include "-" and/or "_" along with alphanumeric in that particular field. I haven't been able to figure out what changes need to be made so that only letters, numbers, - and _ are valid input.
Any help would be appreciated!
I currently have a userform with a textbox that limits the user input to accept only alphanumeric. I had found that code in an older thread on this board here.
The code works great but now I've decided that the user should also be allowed to include "-" and/or "_" along with alphanumeric in that particular field. I haven't been able to figure out what changes need to be made so that only letters, numbers, - and _ are valid input.
Any help would be appreciated!
Code:
Private Sub TextBoxInputComment_Change()
For i = 1 To Len(TextBoxInputComment.Value)
If Mid(TextBoxInputComment.Value, i, 1) Like "*[!0-9A-Za-z]*" Then
strComment = strComment
Else
strComment = strComment & Mid(TextBoxInputComment.Value, i, 1)
End If
Next
TextBoxInputComment.Value = strComment
End Sub