473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Custom Validation Control?

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 onlt 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

Jul 14 '06 #1
0 948

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
0
by: Marek | last post by:
Hi all, I have custrom control with four elements: text box, regular expression validator, required field validator and custom validator. Next this control is dragged on to web site with several...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
1
by: rn5a | last post by:
I have created a custom control button which when clicked displays a message in the JavaScript alert dialog. I could successfully compile the VB class file into a DLL & also could add it to the...
0
by: rn5a | last post by:
A custom control is derived from the WebControl class & encapsulates a TextBox & a Button. When the Button is clicked, the user is shown the JavaScript confirm dialog with the 'OK' & 'Cancel'...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.