CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    139

    how to check if numbers and letters are entered in a textbox

    how do i check textboxes to see whether the user has entered letters, symbols and/or integers? My program requires the user to enter atleast one numeric value, if they don't enter atleast one number then an error message will show. i have tried the following but had no luck:

    // checks password for letters

    private: System::Boolean ValidateInput()

    {

    if (password != "0-9")
    {
    ShowMessage("password must contain atleast one numeric value (0-9).");
    // clear text boxes
    txtPassword->Text = "";
    txtRePassword->Text = "";
    }
    }

    any help will be appreciated thanks
    Last edited by katy_price; November 16th, 2010 at 04:35 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: how to check if numbers and letters are entered in a textbox

    Wrong Forum.
    Try to ask it in Manageged C++/CLI Forum
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2010
    Posts
    47

    Re: how to check if numbers and letters are entered in a textbox

    Well, I imagine you would need to iterate through the letters and check each one until you found a number.
    I'm not sure what your txtPassword variable is, but you can use atoi() to check a character to see if it's a number.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: how to check if numbers and letters are entered in a textbox

    Quote Originally Posted by Ankheg View Post
    Well, I imagine you would need to iterate through the letters and check each one until you found a number.
    I'm not sure what your txtPassword variable is, but you can use atoi() to check a character to see if it's a number.
    You wouldn't want to use atoi. isdigit on the individual characters would be better. I imagine .net has something too, and the correct forum could provide the answer.

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: how to check if numbers and letters are entered in a textbox

    Quote Originally Posted by Ankheg View Post
    [...] you can use atoi() to check a character to see if it's a number.
    A really creative application of that function! And what if the character in question is a '0'?

    No, honestly: GCDEF's suggestion is the method of choice.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured