加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

MFC多字节字符集中使用正则验证姓名等实现方法

发布时间:2020-12-14 00:36:55 所属栏目:百科 来源:网络整理
导读:在VS2010中使用MFC开发,工程为多字节字符集对于中文姓名的增则表达式验证,比较麻烦,我采用了间接的处理方式,验证字符串中不含有数字等进行了处理。 1)cpp中包含 #include regex using namespace std; 2)定义正则表达式 const std::tr1::regex patternP

在VS2010中使用MFC开发,工程为多字节字符集对于中文姓名的增则表达式验证,比较麻烦,我采用了间接的处理方式,验证字符串中不含有数字等进行了处理。

1)cpp中包含

#include <regex>
using namespace std;

2)定义正则表达式

const std::tr1::regex patternPhoneNO("^1[3|4|5|7|8][0-9]{9}$");//手机号
const std::tr1::regex patternName("[0-9?%&=-_]+");//姓名
const std::tr1::regex patternID("(^[1-9]d{7}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}$)|(^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])((d{4})|d{3}[Xx])$)"); //身份证
const std::tr1::regex patternEMAIL("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$");//EMail

3)

//从字符串中正则匹配出结果
BOOL CXXXDlg::RegXScorce(CString strTotal,int flag)
{

BOOL match = false;
std::string s;
s = strTotal.GetBuffer(0);
switch(flag)
{
case 0:
match = std::regex_search(s,patternName);
break;
case 1:
match = std::regex_search(s,patternPhoneNO);
break;
case 2:
match = std::regex_search(s,patternID);
break;
case 3:
match = std::regex_search(s,patternEMAIL);
break;
default:
break;
}

return match;
}



??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读