Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Custom Validation problems

Reply
Thread Tools

Custom Validation problems

 
 
Oded Dror
Guest
Posts: n/a
 
      07-19-2006
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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Summary Validation control with server Custom validation =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= ASP .Net 2 10-15-2004 06:15 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM
validation summary doesnt display when there's client-side validation Libs ASP .Net 0 06-25-2003 03:05 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments