Friday, June 27, 2008

Only numeric validation ( vb.net )

'Only numeric enter in textbox
Private Sub txtPhoneNumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPhoneNumber.KeyPress
Call KeyPressEventTFNum(e.KeyChar, e)
End Sub


Public Sub KeyPressEventTFNum(ByVal ekeychar As String, ByVal e As System.Windows.Forms.KeyPressEventArgs)
'Dim e2 As System.Windows.Forms.KeyPressEventArgs
Dim valid As Int32 = Reg.NumValid(ekeychar)
If valid = 0 Then
e.Handled = False
End If
If valid = 1 Then
e.Handled = True
End If
End Sub


Public Function NumValid(ByVal key_char As String) As Int32
If (Microsoft.VisualBasic.Asc(key_char) <> 57) Then
'e.Handled = True
handel1 = True
End If
If (Microsoft.VisualBasic.Asc(key_char) = 8) Then
'e.Handled = False
handel1 = False
End If
If handel1 = True Then
Return 1
Else
Return 0
End If
End Function

No comments: