Пример #1
0
        public static bool IsValidEmail(string Email)//check if the string follows an email structure
        {
            int AtCount = 0;

            foreach (Char C in Email)
            {
                if (C.ToString() == "@")
                {
                    AtCount++;
                }                                      //Increment the amount of @s in the string
                else if (!NumberSet.Contains(C) && !LowerSet.Contains(C) && !UpperSet.Contains(C) && C.ToString() != ".")
                {
                    return(false);
                }                                                                                                                          //if the character isnt upper,lower or number
            }
            if (AtCount != 1)
            {
                return(false);
            }                                  //If we have more than one @ return false to indicate it is invalid
            if (!Email.Split("@".ToCharArray())[1].Contains("."))
            {
                return(false);
            }                                                                      //If the string after the @ doesnt contain a . return false to induicate it is invalid
            return(true);
        }
Пример #2
0
        public static bool IsValidValueInJsonConfig(string JsonValue)//Check if the value inside the json conforms to our valid charcter set
        {
            Char PrevC            = Char.MinValue;
            int  ClosableBrackets = 0;

            foreach (Char C in JsonValue)
            {
                if (!LowerSet.Contains(C) && !UpperSet.Contains(C) && !NumberSet.Contains(C) && !SpecialSet.Contains(C))
                {//if the character isnt Lower,Upper,Number or special
                    if (C.ToString() == ">" && ClosableBrackets > 0)
                    {
                        ClosableBrackets--;
                    } //where we have the end of a paramater decreas the closable bracket count
                    else if (C.ToString() != "<")
                    { //if it isnt the start or end of a bracket return false to indicate that it is invalid
                        return(false);
                    }
                }
                else if (PrevC.ToString() == "<" && C.ToString() == "@")
                {
                    ClosableBrackets++;
                }                          //Where we have a start of a paramater increase the closable bracket count
                PrevC = C;                 //Set the last character
            }
            return(ClosableBrackets == 0); //If we have closed all paramater brackets
        }
Пример #3
0
 public static bool IsAlphaNumericString(string Str)//Check if all characters in the String are either numbers or letters
 {
     foreach (Char C in Str)
     {
         if (!NumberSet.Contains(C) && !LowerSet.Contains(C) && !UpperSet.Contains(C))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #4
0
        public static bool IsValidPassword(string Password)//Check if the string contains at least 1 capital,number and special
        {
            bool HasNumeric = false, HasCapital = false, HasSpecial = false;

            foreach (Char C in Password)
            {
                if (UpperSet.Contains(C))
                {
                    HasCapital = true;
                }
                else if (NumberSet.Contains(C))
                {
                    HasNumeric = true;
                }
                else if (SpecialSet.Contains(C))
                {
                    HasSpecial = true;
                }
            }
            return(HasCapital && HasNumeric && HasSpecial);
        }