MFC如何让输入框只能输入数字

版权声明:转载请注明出处! https://blog.csdn.net/ZouHuiDong/article/details/89764842

PS:这是本人第一次写CSDN的博客,以后我都会把笔记记在CSDN上,便于保存。本人也是小白,可能写得不好,勿喷!

假设这个输入框添加一个CString变量叫m_strValue

int nLen = m_strValue.GetLength();//获取字符串长度
for(int i=0;i<nLen;i++)//逐个字符进行判断字符的ASCII码是否在48~57之内,即为数字
 {
  if(!((m_strValue.GetAt(i) >= 48) && (m_strValue.GetAt(i) <= 57)) && m_strValue != _T(""))//出现非数字并且字符串非空
  {
   AfxMessageBox(_T("请输入数字!"));
   return ;
  }
 }

猜你喜欢

转载自blog.csdn.net/ZouHuiDong/article/details/89764842
今日推荐