9 September 2010

VB.NET VALIDATION USING ASCII

VB.NET VALIDATION USING ASCII


For Numeric

Public Function OnlyNumeric(ByVal Key As String) As Boolean
If (Key >= 48 And Key <= 57) Or Key = 8 Then
OnlyNumeric = False
Else
OnlyNumeric = True
End If
End Function
--------------------------------------------------------------------------------------------


For Character

Public Function OnlyCharacter(ByVal key As String) As Boolean
If (key >= 65 And key <= 90) Or (key >= 97 And key <= 122) Or key = 8 Then
OnlyCharacter = False

Else
OnlyCharacter = True
MsgBox("Enter only characters")
End If
End Function


-----------------------------------------------------------------------------------------------


create this function and than call this function into that particular "textbox"(KeyPress event) like this way


Private Sub txtcitycode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
e.Handled = OnlyNumeric(Asc(e.KeyChar))
End Sub

Private Sub txtcityname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcityname.KeyPress
e.Handled = OnlyCharacter(Asc(e.KeyChar))
End Sub

No comments:

Post a Comment

Comments Welcome