Custom Validator Control

G

Guest

Dear All,

I want to use a Custom Validator Control on a Text box which accepts only
characters values. I am using the follwing procedure:


Sub CustomValidator_ServerValidate(ByVal s As Object, ByVal e As ServerValidateEventArgs)

If e.Value = "[A-Z]" Then
e.IsValid = True
Else
e.IsValid = False
End If

End Sub

I dont know that whether this is the right code or not. I have tried it
but its not working.

Any help much appreciated.

cheers,
Sunil Sabir
 
W

William F. Robertson, Jr.

You will want something like this. I am c# guy, so syntax might need some
work.

Sub CustomValidator_ServerValidate(ByVal s As Object, ByVal e As
ServerValidateEventArgs)

'this will make sure it hasn't failed before. coding style.
if e.IsValid = false then
exit sub(or return)
end if

dim i as int
for i = 0 to i < e.Value.Length
if System.Char.IsLetter( e.Value, i ) = false then
e.IsValid = false
exit sub ' no point in checking the rest.
end if
End Sub

Or something similar to this.

you [A-Z] comparision will only check the string value to each.

You could use regular expressions, but I didn't type out that sample.

HTH,

bill
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top