首先添加头文件#include
//验证方法
CString str;
my_edit1.UpdateData(FALSE);
my_edit1.GetWindowText(str);
CT2CA tempPassword(str);
std::string strPassword(tempPassword);
std::regex rx("[0-9a-zA-Z]+");
bool bl = std::regex_match(strPassword.begin(),strPassword.end(),rx);
if (!bl)
{
AfxMessageBox(_T(“只允许输入数字或字母”));
}
如果觉得《MFC如何限制文本框只允许输入数字或字母》对你有帮助,请点赞、收藏,并留下你的观点哦!