Kali ini saya akan memberikan cara validasi yang bisa digunakan berulang kali dan bisa disesuaikan dengan mudah tergantung kebutuhan anda beserta contoh penggunaannya yang umum.
1.Validasi input hanya angka:
Public
Sub
NumberValid(KeyAscii
As
Integer
)
Const
Number =
"0123456789"
If
KeyAscii <> 8
And
KeyAscii <> 13
Then
If
InStr(Number, Chr(KeyAscii)) = 0
Then
KeyAscii = 0
Exit
Sub
End
If
End
If
End
Sub
2.Validasi input hanya huruf:
Public
Sub
CharacterValid(KeyAscii
As
Integer
)
Const
Character =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz "
If
KeyAscii <> 8
And
KeyAscii <> 13
Then
If
InStr(Character, Chr(KeyAscii)) = 0
Then
KeyAscii = 0
Exit
Sub
End
If
End
If
End
Sub
3.Validasi input angka dan huruf:
Public
Sub
AlphaNumericValid(KeyAscii
As
Integer
)
Const
Character =
"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz "
If
KeyAscii <> 8
And
KeyAscii <> 13
Then
If
InStr(Character, Chr(KeyAscii)) = 0
Then
KeyAscii = 0
Exit
Sub
End
If
End
If
End
Sub
No comments:
Post a Comment