Validasi Huruf dan Angka Pada Textbox VB 6.0


'Membuat konstanta angka dan huruf
Const angka = "0123456789"
Const huruf = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub

'Event ketika Text1 (Textbox 'Angka saja' menerima input dari keyboard)
Private Sub Text1_KeyPress(KeyAscii As Integer)
'Jika yang ditekan bukan 'backspace' dan bukan 'enter'
If KeyAscii <> 8 And KeyAscii <> 13 Then
    'Di sinilah proses validasinya
    If InStr(angka, Chr(KeyAscii)) = 0 Then KeyAscii = 0
End If
End Sub

'Event ketika Text1 (Textbox 'Huruf saja' menerima input dari keyboard)
Private Sub Text2_KeyPress(KeyAscii As Integer)
'Jika yang ditekan bukan 'backspace' dan bukan 'enter'
If KeyAscii <> 8 And KeyAscii <> 13 Then
    'Di sinilah proses validasinya
    If InStr(huruf, Chr(KeyAscii)) = 0 Then KeyAscii = 0
End If
End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s