Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

determine if zip is alphanum - C#

private bool ZipIsAnAlphaNum(string zip)
        {

        }

Open in new window


criteria:

Contains at least one alpha [a thru z]
Contains at least one integer [0 thru 9]

500 points for first to provide working code for the method above in C#.
ASKER CERTIFIED SOLUTION
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

  public static bool IsValidAlphaNumeric(string inputStr)
        {
            //make sure the user provided us with data to check
            //if not then return false
            if (string.IsNullOrEmpty(inputStr))
                return false;

            //now we need to loop through the string, examining each character
            for (int i = 0; i < inputStr.Length; i++)
            {
                //if this character isn't a letter and it isn't a number then return false
                //because it means this isn't a valid alpha numeric string
                if (!(char.IsLetter(inputStr[i])) && (!(char.IsNumber(inputStr[i]))))
                    return false;
            }

            //we made it this far so return true
            return true;
        }

Open in new window