Reputation: 413
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
Upvotes: 2
Views: 3101
Reputation: 2402
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.
CString strRegex = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$/";
Upvotes: 1