www.webdeveloper.com
Results 1 to 7 of 7

Thread: problem using RangeFieldValidator for strings

  1. #1
    Join Date
    Mar 2004
    Posts
    27

    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.

    Talal

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    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.

  3. #3
    Join Date
    Mar 2004
    Posts
    27
    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

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    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.
    Code:
    <asp:Label 
        				id="lblerrormesg" 
      				Text="this feild is required<br>"
    				runat="server"
    				visible="false" enableViewState="False"
    />

  5. #5
    Join Date
    Mar 2004
    Posts
    27
    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

  6. #6
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Here is a good resource if your interested in learning more about this control.

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

    Regards,
    Andrew Buntine.

  7. #7
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles