Hi everybody,
I want to have only 1 P in textbox.
I already have this:
[code]
Public Function ValidateBankNumber(ByRef strValue As String) As Boolean
Dim blnResult As Boolean
Dim strCheckValue As String
Dim character As String
Dim digitsOnly As Boolean
'Dim ascii As Integer = Convert.ToInt16(By.KeyChar)
strCheckValue = strValue
blnResult = False
digitsOnly = True
Dim i As Integer
Dim intValue As Short
Dim intCount As Short
If UCase(Left(strCheckValue, 1)) = "P" Then 'Giro
strCheckValue = CStr(Val(Right(strCheckValue, Len(strCheckValue) - 1)))
If Len(strCheckValue) <= 7 Or ((UCase(Left(strCheckValue, 1)) = "P") = True) Then
For i = 1 To Len(strCheckValue)
character = Mid(strCheckValue, i, 1)
If character < "0" Or character > "9" Then
digitsOnly = False
Exit For
End If
Next i
blnResult = digitsOnly
Else
blnResult = False
End If
Else 'Bank
If Len(strCheckValue) = 9 Then
For i = 1 To 9
character = Mid(strCheckValue, i, 1)
If character < "0" Or character > "9" Then
digitsOnly = False
Exit For
End If
intValue = CShort(Val(character))
intCount = CShort(intCount + (intValue * (10 - i)))
Next i
If digitsOnly And (intCount Mod 11) = 0 Then
blnResult = True
Else
blnResult = False
End If
Else
blnResult = False
End If
End If
ValidateBankNumber = blnResult
End Function
[/code]
But now it is allowed to have more then 1 p in a textbox But How to make it that it is only allowed to have 1 p?
THX
I want to have only 1 P in textbox.
I already have this:
[code]
Public Function ValidateBankNumber(ByRef strValue As String) As Boolean
Dim blnResult As Boolean
Dim strCheckValue As String
Dim character As String
Dim digitsOnly As Boolean
'Dim ascii As Integer = Convert.ToInt16(By.KeyChar)
strCheckValue = strValue
blnResult = False
digitsOnly = True
Dim i As Integer
Dim intValue As Short
Dim intCount As Short
If UCase(Left(strCheckValue, 1)) = "P" Then 'Giro
strCheckValue = CStr(Val(Right(strCheckValue, Len(strCheckValue) - 1)))
If Len(strCheckValue) <= 7 Or ((UCase(Left(strCheckValue, 1)) = "P") = True) Then
For i = 1 To Len(strCheckValue)
character = Mid(strCheckValue, i, 1)
If character < "0" Or character > "9" Then
digitsOnly = False
Exit For
End If
Next i
blnResult = digitsOnly
Else
blnResult = False
End If
Else 'Bank
If Len(strCheckValue) = 9 Then
For i = 1 To 9
character = Mid(strCheckValue, i, 1)
If character < "0" Or character > "9" Then
digitsOnly = False
Exit For
End If
intValue = CShort(Val(character))
intCount = CShort(intCount + (intValue * (10 - i)))
Next i
If digitsOnly And (intCount Mod 11) = 0 Then
blnResult = True
Else
blnResult = False
End If
Else
blnResult = False
End If
End If
ValidateBankNumber = blnResult
End Function
[/code]
But now it is allowed to have more then 1 p in a textbox But How to make it that it is only allowed to have 1 p?
THX