O
Oded Dror
Hi there,
I have custom validator base on LUHN (MODE10) function for CCNumber look
like this
Sub ValidateCCNumber1(ByVal s As Object, ByVal e As ServerValidateEventArgs)
Dim intCounter As Integer
Dim strCCNumber As String = ""
Dim blnIsEven As Boolean = False
Dim strDigits As String = ""
Dim intCheckSum As Integer = 0
' Strip away everything except numerals
For intCounter = 1 To Len(e.Value)
If IsNumeric(Mid(e.Value, intCounter, 1)) Then
strCCNumber = strCCNumber & Mid(e.Value, intCounter, 1)
End If
Next
' If nothing left, then fail
If Len(strCCNumber) = 0 Then
e.IsValid = False
Else
' Double every other digit
For intCounter = Len(strCCNumber) To 1 Step -1
If blnIsEven Then
strDigits = strDigits & CInt(Mid(strCCNumber,
intCounter, 1)) * 2
Else
strDigits = strDigits & CInt(Mid(strCCNumber,
intCounter, 1))
End If
blnIsEven = (Not blnIsEven)
Next
' Calculate CheckSum
For intCounter = 1 To Len(strDigits)
intCheckSum = intCheckSum + CInt(Mid(strDigits, intCounter,
1))
Next
' Assign results
e.IsValid = ((intCheckSum Mod 10) = 0)
End If
End Sub
This work fine but it only validate CCNumber so I created another Sub for
CCType look like this
Sub ValidateCCtype1()
If CCType1.SelectedItem.ToString = "SelectCard" Then
CCTypeValidator1.Text = "Card not selected"
ElseIf CCType1.SelectedItem.ToString = "AmericanExpress" And
CCNumber1.Text.Length = 15 And Left(CCNumber1.Text, 1) = "3" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Visa" And
CCNumber1.Text.Length = 13 And Left(CCNumber1.Text, 1) = "4" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Visa" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "4" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "MasterCard" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "5" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "DinersClub" And
CCNumber1.Text.Length = 14 And Left(CCNumber1.Text, 1) = "3" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Discover" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "6" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "enRoute" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "2" Then
CCTypeValidator1.Text = " "
Else : CCTypeValidator1.Text = CCType1.SelectedItem.ToString & "
Type is not valid"
End If
End Sub
It works just fine but this is not control! this is for click event on label
control ID = CCTypeValidator1
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call ValidateCCtype1()
End Sub
This code is not dynamic it wait for Button click event to fire up
I have one Combo Box ID = CCType1 and one Text Box CCNumber1
My question is how to make this CCType code for using it as a control like
CCNumber
I put OnServerValidate="ValidateCCNumber1" behind this custom validator
control
Thnaks an advanced
Oded Dror
I have custom validator base on LUHN (MODE10) function for CCNumber look
like this
Sub ValidateCCNumber1(ByVal s As Object, ByVal e As ServerValidateEventArgs)
Dim intCounter As Integer
Dim strCCNumber As String = ""
Dim blnIsEven As Boolean = False
Dim strDigits As String = ""
Dim intCheckSum As Integer = 0
' Strip away everything except numerals
For intCounter = 1 To Len(e.Value)
If IsNumeric(Mid(e.Value, intCounter, 1)) Then
strCCNumber = strCCNumber & Mid(e.Value, intCounter, 1)
End If
Next
' If nothing left, then fail
If Len(strCCNumber) = 0 Then
e.IsValid = False
Else
' Double every other digit
For intCounter = Len(strCCNumber) To 1 Step -1
If blnIsEven Then
strDigits = strDigits & CInt(Mid(strCCNumber,
intCounter, 1)) * 2
Else
strDigits = strDigits & CInt(Mid(strCCNumber,
intCounter, 1))
End If
blnIsEven = (Not blnIsEven)
Next
' Calculate CheckSum
For intCounter = 1 To Len(strDigits)
intCheckSum = intCheckSum + CInt(Mid(strDigits, intCounter,
1))
Next
' Assign results
e.IsValid = ((intCheckSum Mod 10) = 0)
End If
End Sub
This work fine but it only validate CCNumber so I created another Sub for
CCType look like this
Sub ValidateCCtype1()
If CCType1.SelectedItem.ToString = "SelectCard" Then
CCTypeValidator1.Text = "Card not selected"
ElseIf CCType1.SelectedItem.ToString = "AmericanExpress" And
CCNumber1.Text.Length = 15 And Left(CCNumber1.Text, 1) = "3" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Visa" And
CCNumber1.Text.Length = 13 And Left(CCNumber1.Text, 1) = "4" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Visa" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "4" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "MasterCard" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "5" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "DinersClub" And
CCNumber1.Text.Length = 14 And Left(CCNumber1.Text, 1) = "3" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "Discover" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "6" Then
CCTypeValidator1.Text = " "
ElseIf CCType1.SelectedItem.ToString = "enRoute" And
CCNumber1.Text.Length = 16 And Left(CCNumber1.Text, 1) = "2" Then
CCTypeValidator1.Text = " "
Else : CCTypeValidator1.Text = CCType1.SelectedItem.ToString & "
Type is not valid"
End If
End Sub
It works just fine but this is not control! this is for click event on label
control ID = CCTypeValidator1
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call ValidateCCtype1()
End Sub
This code is not dynamic it wait for Button click event to fire up
I have one Combo Box ID = CCType1 and one Text Box CCNumber1
My question is how to make this CCType code for using it as a control like
CCNumber
I put OnServerValidate="ValidateCCNumber1" behind this custom validator
control
Thnaks an advanced
Oded Dror