C ++ to determine whether the mailbox format

Summed up what valid email address format is as follows:
  1. The first character must be a letter, but other characters can only be used 26 uppercase and lowercase letters, 0-9 and _ @ symbol.
  2. must contain one and only one symbol. " ! "
  3 @ post must contain at least three up to a symbol". "
  4. the first character must not be" @ "or". "(a first step has been checked)
  5. allowed" @. " or. @
  6 is not the end of the character "@" or "."
  now put the release out the code I wrote a reference for everyone. The following code tests in VS2005 (UNICODE) by, should it meet the most basic needs of verification:
  // check the validity of characters, including 26 uppercase and lowercase letters, 0-9 and _ @ symbol.
 BOOL JCLoginGameLayer :: IsValidChar (char CH)
{
IF ((CH> = 97) && (CH <= 122)) // 26 is lowercase letters
return to true;
IF ((CH> = 65) && (CH <= 90)) // 26 is uppercase letters
return to true;
IF ((CH> = 48) && (CH <= 57 is)). 9 ~ 0 //
return to true;
IF (CH == CH == || 95 || 45 || 46 is CH == 64 == CH) //_-.@
return to true;
return to false;
}
:: isValidEmail JCLoginGameLayer BOOL (String strEmail)
{
IF (strEmail.length () <. 5) // 26 is lowercase letters
return false;

CH = strEmail char [0];
IF (((CH> = 97) && (CH <= 122)) || ((CH> = 65) && (CH <= 90)))
{
int atCount = 0;
int = 0 atPos;
int dotCount = 0;
for (int I =. 1; I <strEmail.length (); I ++) // 0 has passed is determined from the start. 1
{
CH = strEmail [I];
IF (IsValidChar (CH ))
{
IF (CH == 64) // "@"
{
atCount ++;
atPos = I;
}
the else IF ((atCount> 0) && (== 46 is CH)) // after the @ sign. "" No.
dotCount ++;
}
the else
return to false;
}
//. 6 is not the end character "@" or. "."
IF (== 46 is CH)
return to false;
. // 2 must contain one and only one symbol "!"
@ 3. @ post must contain at least three up to a symbol "."
IF ((atCount! =. 1) || (dotCount <. 1) || (dotCount>3) )
to false return;
.. 5 // not allowed "@.", or @.
int X, Y;
X = strEmail.find ( "@.");
Y = strEmail.find ( "@.");
IF (X> || Y 0> 0)
{
return to false;
}
return to true;
}
return to false;
}
  test results:
  isValidEmail (_T ( "[email protected]")); return TRUE
  isValidEmail (_T ( "_ [email protected]" )); return FALSE
  isValidEmail (_T ( "[email protected]")); return FALSE
  isValidEmail (_T ( "[email protected]")); return TRUE
  isValidEmail (_T ( "[email protected]" )); return TRUE
  isValidEmail (_T ( "[email protected]")); return FALSE
  isValidEmail (_T ([email protected])); return FALSE

Guess you like

Origin www.cnblogs.com/blogpro/p/11446001.html