使用MFC检查电子邮件ID是否正确 [英] check whether email id is correct or not using MFC
本文介绍了使用MFC检查电子邮件ID是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..
我正在验证电子邮件ID,输出出错,当我提供不带"@"的电子邮件ID时,也会出现有效"消息框.不知道出什么问题了,请..帮助我
Hi..
I am doing validation of email id, output is coming wrong, when I give email id without "@" also the "valid" message box appears. Don''t know whats going wrong,, pls.. help me
void CEMailDlg::OnValidate()
{
// TODO: Add your control notification handler code here
CString m_sFrom;
m_sFrom=IDC_EDIT_FROM;
for(int a=0;a < m_sFrom.GetLength(); a++)
{
if(m_sFrom.GetAt(a)!='@';)
{
AfxMessageBox("valid id");
}
else
{
AfxMessageBox("invalid id");
}
}
}
谢谢.
推荐答案
在您的代码中,您必须消除!!从比较中...您正在检查该值是否与@不同,并显示一条VALID消息...
您可以使用...
In your code you must eliminate the ! from the comparison... you are checking if the value is different from @ and showing a VALID message...
You can use...
CString m_sFrom;
GetdlgItemText(IDC_EDIT_FROM, m_sFrom); // here you are getting the right text...
if (m_sFrom.Find("@")!=-1)
{
AfxMessageBox("valid");
}
else
{
AfxMessageBox("Invalid");
}
您可以进行DDX,它更易于交互...
HTH ...
PS:您应该遵循John的建议...正则表达式是可行的方法...我只是按照您的示例更正了您检查字符串内容的方式以及其他几件事...
You could do DDX which is easier to interact...
HTH...
PS: you should follow the advice from John... regex is the way to go... I''ve only followed your sample correcting the way you are checking the contents on the string and a couple of things more...
有多种用于验证电子邮件地址的正则表达式解决方案.您需要的只是一个Google foo.
There are several regex solutions for validating email addresses. All you need is a little google foo.
这篇关于使用MFC检查电子邮件ID是否正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文