Advertisement
Guest User

email.c

a guest
Sep 29th, 2012
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. /*Objetivo desse script é apenas para saber usar expressão regular em C em uma aplicação.
  2. Exemplo: verificar se e-mail é válido.
  3. @autor: Reginaldo
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <regex.h>
  9. #define EXPR_REG ".+@.+\\.[a-z]+"
  10. #define TRUE 1
  11. #define FALSE 0
  12. int VerificaEmail(char email[80])
  13. {
  14.     regex_t reg;
  15.     if(regcomp(&reg,EXPR_REG,REG_EXTENDED|REG_NOSUB) != 0)
  16.         printf("expressão regular invalida!\n");
  17.     else
  18.     {
  19.         if(regexec(&reg,email,0,(regmatch_t *)NULL,0) == 0)
  20.             return TRUE;
  21.         else
  22.             return FALSE;
  23.     }  
  24. }
  25. int main()
  26. {
  27.     char email[80];
  28.    
  29.     printf("digite seu e-mail: ");
  30.     fgets(email,80,stdin);
  31.     if(VerificaEmail(email) == TRUE)
  32.         printf("E-mail válido!\n");
  33.     else
  34.         printf("E-mail inválido!\n");
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement