正则表达式验证邮箱

 #include "regex.h"
bool isEmail(const char *email)
{
    const char *eset = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    regex_t   re;  
    regmatch_t   subs[10];
    regex_t stuRT;
    
    regcomp(&stuRT, eset, REG_EXTENDED);
    int err = regexec(&stuRT, email, (size_t)10, subs, 0);
    
    if (err) {
        
        regfree   (&re);
        return false;
    }
    else 
    {
        regfree   (&re);
        return true;
    }

}

 

posted @ 2013-10-14 15:40  haroel  阅读(361)  评论(0编辑  收藏  举报