Search code examples
vb6

textbox validation in vb6 (disable paste option)


validation on textbox in vb 6.0 i tried

Private Sub Text1_KeyPress(KeyAscii As Integer)    
    If Not (KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeySpace Or (KeyAscii >= Asc("1")     And KeyAscii <= Asc("9"))) Then
    KeyAscii = 0
End If

but now i want that paste option should disable when i right click on textbox


Solution

  • this is quite similar:

    Private Sub Text1_Change()
    
    Dim i As Long, sTemp As String
    
        For i = 1 To Len(Text1)
            If InStr(1, "0123456789", Mid$(Text1, i, 1)) > 0 Then sTemp = sTemp & Mid$(Text1, i, 1)
        Next
    
        Text1 = sTemp
    End Sub