如何在MFC中验证电子邮件ID?
我使用此代码来验证电子邮件 ID,我遇到了一些错误,我不知道如何解决它,,,我是 MFC 新手,,如果我很愚蠢,请原谅我
BOOL CMailDlg::Validate(CString m_sFrom)
{
m_sFrom = NulltoString(m_sFrom);
CString strRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
Regex re = new Regex(strRegex);
if (re.IsMatch(m_sFrom))
return (true);
else
return (false);
}
错误:
错误 C2511:“验证”:在“CMailDlg”中找不到重载成员函数“int(CString 类)”
参见“CMailDlg”声明
错误 C2059:语法错误:“数字后缀错误”
错误 C2018:未知字符“0x40”
错误 C2017:非法转义序列
I used this code for validating email id , im getting few errors i dono how to solve it,,, im new to MFC,, if im silly pls forgive me
BOOL CMailDlg::Validate(CString m_sFrom)
{
m_sFrom = NulltoString(m_sFrom);
CString strRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
Regex re = new Regex(strRegex);
if (re.IsMatch(m_sFrom))
return (true);
else
return (false);
}
Errors:
error C2511: 'Validate' : overloaded member function 'int (class CString)' not found in 'CMailDlg'
see declaration of 'CMailDlg'
error C2059: syntax error : 'bad suffix on number'
error C2018: unknown character '0x40'
error C2017: illegal escape sequence
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将正则表达式字符串包含在引号中并转义 \。 C++ 没有对正则表达式的本机支持,就像 Perl 一样,它是使用字符串实现的。 \ 是 C++ 转义字符,用于将新行等内容包含到字符串中,因此如果您想要在字符串中包含实际的 \,则必须将其加倍。
You will need to include the regex string in quotes and escape the \. C++ doesn't have native support for regex as you might find is say Perl, it is implemented using a string. \ is the C++ escape character and used to include things like new lines into strings, as such if you want an actual \ in your string you must double it up.