HOW TO I GET MY TEXTBOX TO ONLY ALLOW NUMBERS 1-14?

Lillian Martin

Total Post:27

Points:189
Posted by  Lillian Martin
 803  View(s)
Ratings:
Rate this:

This is what i have so far, but I am obviously getting an error.

 

try

{

    dblNights = Convert.ToDouble(txtNights.Text);

 

    if (dblNights > 1 && 14)

    {

    }

    else

    {

        string script = "alert(\"Number of Nights Must be between 1 and 14!\");";

        ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);

        txtNights.Focus();

    }

}//End Try

 

catch

{

    string script = "alert(\"Number of Nights Must be an Integer!\");";

    ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);

 

    txtNights.Focus();

}//End Catch

I am not quite sure what to do to make show an error box if numbers besides 1-14 are entered. Everything else is working, just not that. What am I doing wrong?

 

Thank you.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to i get my textbox to only allow numbers 1-14?

    You are not properly using the Logical AND operator.

    This:

           if (dblNights > 1 && 14)

            {

            }

    Must be:

           if (dblNights >= 1 && dblNights <= 14)

            {

                 /*valid range some thing here*/

            }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!