June 4, 2012

Function to check key validation using asp.net

Function to check key validation using asp.net

 ublic Function KeyValid(ByVal keyChar As Char, ByVal strType As KeyType) As Boolean  
 Dim blnRetVal As Boolean  
 Dim strNumStr As String = "0123456789"  
 Dim strDecStr As String = "0123456789."  
 Dim strAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"  
 Dim strDate As String = "0123456789/"  
 Dim strPhone As String = "0123456789-(),"  
 Dim strTime As String = "01234567890:"  
 Dim strEqn As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./*+-()|"  
 Dim strAlphaNum As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"  
 Try  
 blnRetVal = False  
 If Asc(keyChar) < 32 Then KeyValid = False Exit Function End If Select Case strType Case KeyType.KeyAlpha If strAlpha.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyAlphaNum If strAlphaNum.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyDate If strDate.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyDecimal If strDecStr.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyNumber If strNumStr.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyPhone If strPhone.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyTime If strTime.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyEqn If strEqn.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal End Select KeyValid = blnRetVal  
 Catch ex As System.Exception  
 MsgBox(ex.Message.ToString.Trim, , "ABC") End Try End Function #End Region