+ char email[strlen(org_email)+1];
+ strcpy(email, org_email);
+ //validate email address
+ //1st check: there need to be one @
+ char *p1 = strchr(email, '@');
+ if(!p1 || strchr(p1+1, '@')) return 0;
+ *p1 = '\0';
+ //2nd check: username (bevore @) must be at least 1 char long and out of part_chars
+ char *part_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._%+-";
+ int i;
+ if(p1 - email == 0) return 0;
+ for(i = 0; i < (p1 - email); i++) {
+ if(!strchr(part_chars, email[i])) return 0;
+ }
+ //3rd check: there need to be at least 1 dot in the domain part and all characters out of part_chars
+ part_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
+ char *p2 = NULL;
+ p1++;
+ i = 0;
+ while(*p1) {
+ if(*p1 == '.') {
+ if(!i) return 0;
+ i = 0;
+ p2 = p1;
+ } else if(!strchr(part_chars, *p1))
+ return 0;
+ else
+ i++;
+ p1++;
+ }
+ if(!p2) return 0;
+ //4th check: TLD must be <= 5 chars, no special chars
+ i = 0;
+ p2++;
+ while(*p2) {
+ if(!isalpha(*p2))
+ return 0;
+ else
+ i++;
+ p2++;
+ }
+ if(i > 5) return 0;
+ return 1;