Thread: edit control - testing input

  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003

    edit control - testing input

    Hi, I've made MFC application that performs calculations with numbers entered from edit controls.
    For example:
    CString var1,var2;
    double var1double,var2double;
    Problem arises when user enters some characters or string
    when he's supposed to enter number.
    For example value 5.52 is expected and user enters "dfsd". Function atof() will work and I'll get some dummy values in further calculations.
    My question is how to check if value that is entered (in form string) really number or not?

    Is there any way to check what is entered and to notify user to try again if number is not enetered.
    Thanks for help!

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    use the isdigit function and test the string, something like so:

      int length=strlen(buff);
      for(int a=0;a<length;a++)
      	 if(!isdigit(buff[a]) && buff[a]!='.')
      if(a!=length)  // Quit prematurely....must contain invalid characters
      // do stuff
    mrrk, that code's written in C, but you should be able to figure out the C++ equivalent for your code

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Thanks dude

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  3. Problems with my edit control...
    By tyouk in forum Windows Programming
    Replies: 19
    Last Post: 10-19-2003, 12:36 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Input Control
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 01-15-2002, 06:21 PM