Click to See Complete Forum and Search --> : problem using RangeFieldValidator for strings


talal
05-02-2004, 12:03 PM
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.

Talal

buntine
05-02-2004, 12:18 PM
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.

Regards.

talal
05-02-2004, 02:22 PM
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.

Talal

PeOfEo
05-02-2004, 04:28 PM
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
lblerrormsg.visible="true"
else
<code to be executed if the textbox length is how you wanted it>
end if

lblerrormsg would be an asp lable right after your text box.

<asp:Label
id="lblerrormesg"
Text="this feild is required<br>"
runat="server"
visible="false" enableViewState="False"
/>

talal
05-02-2004, 06:20 PM
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.

Thanks,
Talal

buntine
05-02-2004, 08:22 PM
Here is a good resource if your interested in learning more about this control.

http://www.codeproject.com/aspnet/validator.asp?msg=808604

Regards,
Andrew Buntine.

PeOfEo
05-02-2004, 11:07 PM
Originally posted by talal
RangeValidator to use, it looks a good control if I figure out to use in this scenario.

Thanks,
Talal 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.