Max Length Custom Control

G

Guest

Does anyone have a good example of a custom validator for max and min length
validation?
 
G

Guest

Rather than creating your own custom control, an easier way would be to just
drop a custom validator control on your page and use it's Server_Validate
event to check the lengths of your strings.

private void vldOrder_ServerValidate( Object source,
ServerValidateEventArgs args)
{
if (txtZip.Text.Length < 5 || txtZip.Text.Length > 9){
args.IsValid = false;
vldOrder.ErrorMessage = "Zip/Postal Code must be between 5 and 9
characters long";
return;
}
}

HTH
 
G

Guest

Mike, I'm curious: Is there any problem with the regular expression I posted
to your question a few days ago? I'd like to do something similar myself, so
am wondering if that breaks down somewhere. To get your "custom control", I'd
think you could derive from regularexpressionvalidator, pass the min and max
lengths, and format the regular expression from there.

Bill
 
G

Guest

Woops, actually there is already a "Range Validator" control in your toolbox
that allows you test the ranges of various data types. This would work just
like the other validation controls where you would have to attach it to a
field on your form.
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top