Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Objetivo desse script é apenas para saber usar expressão regular em C em uma aplicação.
- Exemplo: verificar se e-mail é válido.
- @autor: Reginaldo
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <regex.h>
- #define EXPR_REG ".+@.+\\.[a-z]+"
- #define TRUE 1
- #define FALSE 0
- int VerificaEmail(char email[80])
- {
- regex_t reg;
- if(regcomp(®,EXPR_REG,REG_EXTENDED|REG_NOSUB) != 0)
- printf("expressão regular invalida!\n");
- else
- {
- if(regexec(®,email,0,(regmatch_t *)NULL,0) == 0)
- return TRUE;
- else
- return FALSE;
- }
- }
- int main()
- {
- char email[80];
- printf("digite seu e-mail: ");
- fgets(email,80,stdin);
- if(VerificaEmail(email) == TRUE)
- printf("E-mail válido!\n");
- else
- printf("E-mail inválido!\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement