problem using RangeFieldValidator for strings
I am trying to use RangeFieldValidator for a username and password. The username suppose to be at least three characters long and the password at least five characters long. I am using the datatype as string, validating the textbox correctly, but I don't know how to set the minimum and maximum values for the string.
I think I can't use 3 and 5 for the min and max values, since it is string datatype.
Any help will be appreciated.
All you have to do is check whether the length of the string is greater than or equal to the minimum length for usernames using an if statement.
I add the onclick event in the RangeValidator to go to the function check_length. And used the .Length method of string to compare the length of input.
But when I start typing in the TextBox1 it shows the RangeValidator ErrorMessage even if the length is correct. I guess this is because the onclick event.
Should I use a different event. I am totally new to .Net and scripting language, so please help me out.
I do not use the validators myself, I do not like them because asp.net otuputs js with them and it outputs a bit of invalid code. Here is what I would do, I would put in the script that you are executeing on click of that command button at the bottom, as buntine said, and if statement
if len(yourtextbox) < 3 and len(youtextbox) > 5 then
<code to be executed if the textbox length is how you wanted it>
lblerrormsg would be an asp lable right after your text box.
Text="this feild is required<br>"
Thanks PeOfEo and buntine; I did what you guys told and solve the problem, using the if statement and label to display error message.
But, I am trying to figure out the RangeValidator to use, it looks a good control if I figure out to use in this scenario.
Here is a good resource if your interested in learning more about this control.
None of the validators are 'good' controls in my opinion. They are bad until version 1.1 if microsoft decides to fix their output. I do not use the built in pageing and some of the other built in features either, because they limit me and output js that does not have a type attribute.
Originally posted by talal
RangeValidator to use, it looks a good control if I figure out to use in this scenario.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)