Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to verify why user input?

Posted on 2001-06-05
11
Medium Priority
?
262 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

609 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