0

email verifiction

whats missing.........? #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> int valid_mail(char x[]); int main() { do{ char mail[100]; gets(mail); }while(valid_mail(mail)==-1); return 0; } int valid_mail(char x[]) { int count=0; int countp=0; int i,j; int t,t2; int k=0; for(i=0 ; i<strlen(x) ; i++) { if(x[i]=='@') { count++; t=i; } } if(count==1) { for(j=0; j<t ; j++) { if(!(x[j]=='_' || x[j]=='.' || isalpha(x[j]) || isdigit(x[j]))) { k=-1; printf("\nInvalid e-mail\n"); break; } } if(k==0) { for(i=0; i>t ; i++) { if(x[i]=='.') { t2=i; countp++; } } if(countp==1) { for(i=0; i<t2 && i>t2; i++) { if(!(isalpha(x[i]))) { k=-1; printf("\nInvalid e-mail\n"); break; } else { k=1; } } if(k==1) { if(x[t2+3]!='\0') { k=-1; printf("\nInvalid e-mail\n"); } } } else { k=-1; printf("\nInvalid e-mail\n"); } } } else { k=-1; printf("\nInvalid e-mail\n"); } return k; }

4th Oct 2018, 3:09 PM
Ridham Nitin Chhadwa
Ridham  Nitin Chhadwa - avatar
1 Answer
0
Try using a regex :)
5th Oct 2018, 6:56 AM
Sam Pache
Sam Pache - avatar