textbox

Last post 03-25-2008 3:22 PM by smcirish. 8 replies.

Sort Posts:

  • textbox

    03-25-2008, 12:05 PM
    • Loading...
    • joynee
    • Joined on 02-14-2008, 3:26 PM
    • Posts 116

    how to validate a textbox to accept only numbers from 0-9.other than letters

  • Re: textbox

    03-25-2008, 12:09 PM
    Answer
    • Loading...
    • XIII
    • Joined on 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 9,542
    • Moderator
      TrustedFriends-MVPs

    Hi,

    use a RangeValidator control like this:

    <asp:TextBox runat=server ID=TextBox1></asp:TextBox>
     <asp:RangeValidator runat=server ID=RangeValidator1 ControlToValidate=TextBox1
                MaximumValue=9 MinimumValue=0 ErrorMessage="*" Type="Integer"></asp:RangeValidator>

    Grz, Kris. 

    Read my blog | Members are volunteers so please keep out the (it's urgent | asap | reply me directly) stuff. Nobody's interested in that.
  • Re: textbox

    03-25-2008, 12:11 PM
    Answer
    • Loading...
    • scommisso
    • Joined on 07-02-2004, 12:11 AM
    • Phoenix, AZ, USA
    • Posts 139

    I would use a RegularExpressionValidator like so:

     

    <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
      runat="server" ControlToValidate="TextBox1"
      ErrorMessage="Must be all numbers"
      ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
     
    Steve Commisso
    MCSD.NET, MCPD: EAD
  • Re: textbox

    03-25-2008, 12:14 PM
    • Loading...
    • XIII
    • Joined on 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 9,542
    • Moderator
      TrustedFriends-MVPs

    Oops I misinterpreted the question as I thought you would only need a cipher between 0 - 9. If you need indeed a sequence of ciphers and you know the highest possible value you can also use that to set the MaximumValue property to that.

    Grz, Kris. 

    Read my blog | Members are volunteers so please keep out the (it's urgent | asap | reply me directly) stuff. Nobody's interested in that.
  • Re: textbox

    03-25-2008, 12:30 PM
    • Loading...
    • joynee
    • Joined on 02-14-2008, 3:26 PM
    • Posts 116

    do i need to write anythg in the back end C# code?

  • Re: textbox

    03-25-2008, 12:37 PM
    • Loading...
    • XIII
    • Joined on 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 9,542
    • Moderator
      TrustedFriends-MVPs

     

    joynee:
    do i need to write anythg in the back end C# code?

    No, just add the validation control you need, set the correct properties and you're good to go.

    Grz, Kris. 

    Read my blog | Members are volunteers so please keep out the (it's urgent | asap | reply me directly) stuff. Nobody's interested in that.
  • Re: textbox

    03-25-2008, 12:39 PM
    • Loading...
    • schuelter
    • Joined on 08-21-2007, 11:52 AM
    • Blumenau, Santa Catarina, Brazil
    • Posts 80

    No, the Validator controls do everything for you... Does it not working?

    Regards,
    Eduardo Schuelter - MCP, MCAD, MCSD .NET, MCTS, MCPD
  • Re: textbox

    03-25-2008, 2:27 PM
    • Loading...
    • joynee
    • Joined on 02-14-2008, 3:26 PM
    • Posts 116

    thanq its working

  • Re: textbox

    03-25-2008, 3:22 PM
    Answer
    • Loading...
    • smcirish
    • Joined on 04-16-2007, 5:27 PM
    • Texas
    • Posts 199

    You can use a range validation check.

     For other kinds of data cleanup/special characters, see this post.

    http://forums.asp.net/t/1174006.aspx

     

    ~ Remember To Mark The Posts Which Helped You As The ANSWER ~
    Filed under:
Page 1 of 1 (9 items)