help on field length validation using RangeValidator

  • Thread starter François Ligouy
  • Start date
F

François Ligouy

On page 17 of module 7 ("Validating user input") of the document called
"Developping Microsoft ASP.NET web applications using Visual Studio.NET"
which is given to students who attend official training sessions on the
subject, I've read subsequent characteristics concerning the Range Validator
control :
"RangeValidator has the following properties :
"Minimum value", which specifies the minimum value of the valid range for
numeric variables, or the minimum character length of the string for string
variables
"Maximum value", which specifies the maximum value of the valid range for
numeric variables, or the maximum character length of the string for string
variables

The first usage ("valid range for numeric variables") works fine.

I've tried to implement the second usage (minimum/maximum character length
for string variables); unfortunately, this does'nt appear to work.
Can someone let me know how to make it work or confirm to me what I srongly
suspect : despite what the Microsoft document reads, validation of character
length functionality can only be implemented using a custom validator.

Thanks to anyone's help on the matter.
 
F

François Ligouy

Thanks for your answer, Peter. A RegularExpressionValidator is actually a
better solution than having to write a custom validator. That will do fine
for the intranet development I'm in for the time being, because everyone is
using Internet Explorer in this one.
For internet developments, I will seriously consider your "Professional
Validation And More". I've just had a look at it and decided to bookmark it
at once.



Peter Blum said:
That information is incorrect. RangeValidator does not check text length.

Here are a couple of solutions:
1. Use a RegularExpressionValidator with the expression set to:
^[\S\s]{minimum, maximum}$
where minimum and maximum are replaced by your length limits

2. I built a replacement to Microsoft's validators, Professional
Validation And More (http://www.peterblum.com/vam/home.aspx). Amongst its
22 validators is a TextLengthValidator with a couple of improvements over
the above solution:
- The error message can include tokens that are replaced by the minimum,
maximum and current length values. So its an interactive message.
- Its faster because it checks the actual text length instead of setting
up and running a regular expression. (Both server and client-side speed.)
- It, like all my validators, supports many more browsers when using
client-side validation.
I wrote Professional Validation And More because I found so many
limitations in Microsoft's validators that required writing custom code
and hacks. You can see what I learned about those limitations here:
http://www.peterblum.com/vam/valmain.aspx. It will help you plan your
site's validation design better.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

François Ligouy said:
On page 17 of module 7 ("Validating user input") of the document called
"Developping Microsoft ASP.NET web applications using Visual Studio.NET"
which is given to students who attend official training sessions on the
subject, I've read subsequent characteristics concerning the Range
Validator control :
"RangeValidator has the following properties :
"Minimum value", which specifies the minimum value of the valid range for
numeric variables, or the minimum character length of the string for
string variables
"Maximum value", which specifies the maximum value of the valid range for
numeric variables, or the maximum character length of the string for
string variables

The first usage ("valid range for numeric variables") works fine.

I've tried to implement the second usage (minimum/maximum character
length for string variables); unfortunately, this does'nt appear to work.
Can someone let me know how to make it work or confirm to me what I
srongly suspect : despite what the Microsoft document reads, validation
of character length functionality can only be implemented using a custom
validator.

Thanks to anyone's help on the matter.
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top