Custom Validation problems

Discussion in 'ASP .Net Building Controls' started by Oded Dror, Jul 19, 2006.

  1. Oded Dror

    Oded Dror Guest

    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, Jul 19, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,701
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,523
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,140
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Using Summary Validation control with server Custom validation

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    891
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 15, 2004
Loading...

Share This Page