Skip to content

Instantly share code, notes, and snippets.

@codemercenary
Last active December 17, 2015 02:45
Show Gist options
  • Save codemercenary/17df1c75dcb76e02d7c1 to your computer and use it in GitHub Desktop.
Save codemercenary/17df1c75dcb76e02d7c1 to your computer and use it in GitHub Desktop.
Stub program to validate an E-mail address
#include <cstdio.h>
int main(int argc, const char* argv[]) {
if(argc != 2)
return 1;
const char* email = argv[1];
// A valid E-mail address is actually quite complex. You will be writing a function will validate a
// subset of these rules. Here, a valid E-mail address will be defined by the following grammar:
//
// email :- localpart '@' domain
// localpart :- piece | localpart '.' piece
// piece :- [a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+
// domain :- hostnamepart | domain '.' hostnamepart
// hostnamepart :- [a-zA-Z0-9-]+
//
// The following restrictions also apply:
// domain: Cannot be more than 253 characters
// localpart: Cannot be more than 64 characters
// email: Cannot be more than 254 characters
// TODO: Return 0 for a bad E-mail address, return 1 for a good one
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment