?
Solved

How to verify why user input?

Posted on 2001-06-05
11
Medium Priority
?
248 Views
Last Modified: 2013-11-20
Is there any function to verify user input??

eg. User key in something in the edit box, after press a button, I want to check what user had type in, whether numeric numbers or characters.

What I need to do??
0
Comment
Question by:jason_nothing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6155397
Hi jason_nothing,

you can do  i.e.:

- add a EN_CHANGE notification message handler for the edit control to the parent window's class,
there parse the string and modify if needed as you want it to be...
- derive your own class from CEdit and override a WM_CHAR message handler to filter out
keys which shouldn't be allowed.


ZOPPO
0
 

Author Comment

by:jason_nothing
ID: 6155462
Hi ZOPPO,

I don't quite get what you mean, can you give an example in more details?? thanks
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6155463
Using isdigit(int c). isdigit returns a non-zero value if c is a decimal digit (0 ? 9).
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:jason_nothing
ID: 6155494
GloriosRain,
 
Can you show me more details on how to use the isdigit()??
0
 
LVL 12

Expert Comment

by:migel
ID: 6155539
hi!
look at www.codeguru.com editcontrol section for mask edit articles
0
 

Author Comment

by:jason_nothing
ID: 6158237
It don't have any single function in MFC that can do this ?

0
 

Expert Comment

by:alortiz
ID: 6160839
Easy solution:

You need to create an event handler to do that checking.

If you are using the classwizard, create and map a member variable to the edit control, then select the event you want to catch (ie onclick for the button), and create a new functin for it. that fucntion will be evaluated whenever the even happens, from there you can check the data typed in the text box (by using the edit control propperties), etc.
However, if this functionality will be frecuently desired, you should derive a class from CEdit, to do pretty much the same as above, but using only the Edit control events

0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6162058
e.g of isdigit(int c)
...
CString strTest("a123");
for (int i = 0; i < strTest.GetLength(); i++)
   if (isdigit(strTest[i]))
   {
      CString s;
      s.Format("%c", strTest[i]);
      AfxMessageBox(s);
   }
...
you can use isalpha(int c) to check character.
isalpha returns a non-zero value if c is within the ranges A ? Z or a ? z.
0
 
LVL 2

Accepted Solution

by:
GloriousRain earned 480 total points
ID: 6162071
Hi jason_nothing,
Try this class, it's inherit from CEdit. It will checks character input with specific filter whenever user press a key in editbox. I have an example at bottom.

//MyEditCtrl.cpp
/////////////////////////////////////////////////////////////////////////////
// CMyEditCtrl

// bFilter = TRUE will filter out all chars in strFilter
// bFilter = FALSE will allow only those chars in strFilter
CMyEditCtrl::CMyEditCtrl(CString strFilter, BOOL bFilter)
     : m_bFilter(bFilter), m_strFilter(strFilter)
{
}

CMyEditCtrl::~CMyEditCtrl()
{
}

BEGIN_MESSAGE_MAP(CMyEditCtrl, CEdit)
     //{{AFX_MSG_MAP(CMyEditCtrl)
     ON_WM_CHAR()
     //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyEditCtrl message handlers

void CMyEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
     if (nChar > 32 && nChar < 127)
     {
          if ((m_bFilter && m_strFilter.Find(nChar) != -1) ||
             (!m_bFilter && m_strFilter.Find(nChar) == -1))
          {
               MessageBeep(0xFFFFFFFF);
               return;
          }
     }
     CEdit::OnChar(nChar, nRepCnt, nFlags);
}

//MyEditCtrl.h
class CMyEditCtrl : public CEdit
{
// Construction
public:
     CMyEditCtrl(CString strFilter, BOOL bFilter=FALSE);

// Attributes
private:
     CString m_strFilter;
     BOOL     m_bFilter;

// Operations
public:
     const CString&     GetFilterString() const;
               void     SetFilterString(const CString &strFilter);
               BOOL     GetFilter() const;
               void     SetFilter(BOOL bFilter);

// Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CNtlEditCtrl)
     //}}AFX_VIRTUAL

// Implementation
public:
     virtual ~CMyEditCtrl();

     // Generated message map functions
protected:
     //{{AFX_MSG(CMyEditCtrl)
     afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
     //}}AFX_MSG

     DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

inline const CString& CMyEditCtrl::GetFilterString() const
{
     return m_strFilter;
}

inline void CMyEditCtrl::SetFilterString(const CString &strFilter)
{
     m_strFilter = strFilter;
}

inline BOOL CMyEditCtrl::GetFilter() const
{
     return m_bFilter;
}

inline void CMyEditCtrl::SetFilter(BOOL bFilter)
{
     m_bFilter = bFilter;
}

Here is example of above class:
CMyEditCtrl m_eIPAddress(_T("1234567890."));
0
 

Author Comment

by:jason_nothing
ID: 6162225
I think GloriousRain's answer was excellent!! very clear and details, so I have to reject your answer. Anyway, thanks for the comment.
0
 

Author Comment

by:jason_nothing
ID: 6162261
Hi GloriousRain,

    U are excellent, I can't did it without your help...thanks a lot!!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question