That is because you forgot to escape the closing square bracket in the character group and that they must be double escaped (so that a backslash is placed in the string to be seen by the regex parser):
wrong: "[!/\[]:;|=,+*<>]*"
correct: "[!/\\[\\]:;|=,+*<>]*"
You also don't need to convert the input to ANSI when using the
wregex
class provided by Visual C++:
bool ValidateLoginid(const CString& inputString)
{
std::wregex stringpattern(L"[!/\\[\\]:;|=,+*<>]*");
return !std::regex_match(inputString.GetString(), stringpattern);
}
Note also that I have changed the parameter to be a const reference to avoid passing by value and indicate that it is not changed.
There is also no need to use a regular expression if you only want to check if specific characters are present or not. Then just use
strstr
or
CString::FindOneOf
.