Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Oded Dror #1
Custom Validation problems
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
Oded Dror Guest
-
CFFORM validation trumping Custom Validation
Is there any way for custom form validation to work in concert with the cfform validation? I have a custom script that compares the values of two... -
CFFORM Validation trumping Custom Form Validation
Is there any way for custom form validation to work in concert with the cfform validation? I have a custom script that compares the values of two... -
Custom WebXel Custom Validation
First....Thank You Kevin for providing such a useful tool. It works great! Now, I may be missing something, but I studied some of the canned... -
Validation on custom controls
Hi, I searched through NG's etc but could not find an answer to my problem..... I have a custom control that consists of 3 textboxes. I would... -
only custom validation control does server side validation?
On a CustomValidator you have to provide the validation code because otherwise it doesn't know what to do for the validation. Other validator...



Reply With Quote

