Cocos2d-x学习笔记(一)

2023-01-04 14:34:44 浏览数 (1)

Cocos2d 中一些验证正则表达式:

邮箱:

代码语言:javascript复制
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
        regex pattern("([0-9A-Za-z\-_\.] )@([0-9a-z] \.[a-z]{2,3}(\.[a-z]{2})?)");
        if (! std::regex_match(m_pRegEmail->getText(), pattern)){
代码语言:javascript复制
            return false;
        }
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        
        std::regex_t match_regex;
        regcomp(&match_regex,"([0-9A-Za-z\-_\.] )@([0-9a-z] \.[a-z]{2,3}(\.[a-z]{2})?)",REG_EXTENDED);
        if (regexec(&match_regex, m_pRegEmail->getText(), 0, NULL, 0) != 0){
            return false;
        }
        regfree(&match_regex);
#endif

是否包含英文:

代码语言:javascript复制
bool includeChinese(const char *str)
{
    char c;
    while (1)
        {
        c = *str  ;
        if (c == 0) break;   //
        if (c & 0x80)        //
            if (*str & 0x80) return true;
        }
    return false;
}

0 人点赞