I have this code that is supposed to verify email adresses and i have nearly perfected it. The problem with it is that the period can be anywhere and my program will say its valid. For example if i input Albert.var@gmail then it will mark it as correct. Help?
Is this for fun or do you actually need to verify the validity of the address? The correct way to verify an email address is to check if it matches the regular expression in RFC822: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
// rudimentary. see: https://en.wikipedia.org/wiki/Email_address#Syntaxbool valid( std::string address )
{
std::size_t at = address.rfind('@') ; // find the last '@'
if( at == std::string::npos ) returnfalse ; // no '@'
std::size_t dot = address.find( '.', at ) ; // find '.' after the last '@'
if( dot == std::string::npos ) returnfalse ; // no '.' after the '@'
return dot < address.size() - 1 ; // true if there is at least one character more, after the dot
}