Hello, I am running a program that makes the registration of users with their e-mail address. It makes the registration using mysql. The problem is that when someone types the e-mail address with special characters, such as {, ƒ and so on, the program gets killed, returning syntax error in mysql. I was wondering if someone could help me fixing the code. I tried several ways, but could not make it. Here is the code: Code: int validate_email(const char *email) { if (strchr(email, '\\')) return 0; else if (strchr(email, '\"')) return 0; else if (strchr(email, '\'')) return 0; else if (strchr(email, '@') && strchr(email, '.')) return 1; else return 0; } With this code I can filter \, ' and ", but not other special chars. Thank you!!
Code: #include <ctype.h> #include <string.h> int validate_email(char* mailaddr) { /* allow alpha, digits, @ and underscore - you can modify this to include other permissible characters */ int i, reply = 1, c; for( i = 0; i < strlen(mailaddr) && reply; i++ ) { c = mailaddr[ i ]; if( ! isalpha(c) && ! isdigit(c) && c != '@' && c != '_' ) reply = 0; } return reply; }