Programming Concepts II – Assignment 2 – String Manipulation
This assignment is an exercise in using string manipulation to edit and reformat input fields. Some fields have patterns, some expect numeric values … possibly with limits. Some fields are required (and cannot be just spaces), some are optional or conditionally optional, some will cause abends if null is not expected. Strings need to be trimmed of leading and trailing blanks, shifted to upper- or lower-case or capitalized.
This is also an exercise in creating and using reusable code … i.e. code usable by multiple projects.
Wherever you see “XX”, replace it with your initials
⦁ Create a XXValidation class with the following static methods:
⦁ XXCapitalize – this takes a string parameter and returns a string. Return an empty string if the input is null or empty. It should trim leading and trailing spaces, and change the first letter of each word (if it is a letter) to upper case and the remaining letters in each word to lowercase. Watch 1-letter words.
⦁ XXMemberCodeValidation - This takes a string and returns a Boolean. If the incoming string is null or an empty string, throw an exception. Otherwise, return true if the string is 9 characters long and contains exactly 5 numbers and 4 upper-case letters in any order: “AAAA66666” & “5A5A5AA55” are both valid.
⦁ XXPhoneNumberValidation – this takes a string and returns a Boolean. If the incoming string is null or empty, throw an exception. Otherwise, return true only if the entire string fits the phone pattern “123 123 1234” or “123.123.1234”. Note for the space separator or period separator, either one can be used but not both (e.g. 123 123.1234 would be incorrect).
⦁ XXUKPostalValidation – this takes a string by reference and returns a Boolean. If the incoming string is null or empty, throw an exception. Otherwise, return true only if the string’s entire content fits the UK postal pattern “A[A]3[A/3] 3AA” (where “3” represents any digit, “A” represents any letter, [A] represents an optional letter, and [A/3] represents an optional letter or digit). Accept upper or lower case, with or without the space. If valid, shift the input string to uppercase characters and insert the space, if missing.
⦁ Create the following form, naming it XXGymMemberManagement.cs
⦁ Pre-Fill” loads the form with valid data … making it easier to test individual field errors.
⦁ Use this string as the Pre-Fill value for the “Member Goal” field:
“To Run 126 mileS; in 2 hours. Perform 300 situps, and Squat 100 pOUNDS, by January of 2022.”
⦁ “Submit” edits the current data on the form and reformats the fields back onto the form, if necessary.
⦁ All validation errors are displayed together on the form in a red label (the preferred option), rich text box or in a message box … one line per error, with focus to the first field in error.
⦁ “Close” closes the form and “Clear” clears all the fields.
⦁ Tab sequence should be down the top rows and the left column, then down the right column and the buttons.
⦁ Perform the following validations (all fields are optional unless specified otherwise). All error messages are to be shown at once, one line per error, focus moved to the first field in error.
⦁ A non-blank Member Code is required. Use XXMemberCodeValidation to check for invalid code and return any error messages.
⦁ “Full name” is required and must contain more than one name (e.g. First Name and Last Name).
⦁ “Mailing address” is not required if “Town” is populated
⦁ “Town” is required only if “Province Code” begins with an “O” or an “A” - and must be more than 3 characters … not counting digits and spaces.
⦁ Use your XXPhoneNumberValidation method to verify all phone number(s) provided.
⦁ If an email is provided, Cell Phone is not required - otherwise Cell Phone is required.
⦁ The email must be a valid email pattern, if provided. There’s a MailAddress class in the System.Net.Mail namespace that throws an exception when instantiated with an invalid email address. There’s also a plethora of indecipherable regular expressions out there.
⦁ The province code, if provided, must be exactly two letters, not just two characters. Accept upper- and lower-case.
⦁ The Date Joined cannot be in the future and displayed in the format YYYY MMM DD.
⦁ The Postal code is required. Use XXUKPostalValidation to validate and update the postal code.
⦁ Perform the following data conversions
⦁ Use your XXCapitalize method to format the Member Goal, Mailing Address, Town and Full name fields.
⦁ Remove all punctuation characters from Member Goals except the period(“.”).
⦁ Shift the province code to uppercase.
⦁ Shift the email to lowercase (it’s still valid, but easier to use for comparisons).
⦁ The Postal code should be reformatted by XXUKPostalValidation.
⦁ Zip and upload your project folder to the assignment 2 drop-box for this course.