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.
- Create the following form, naming it XXMember.cs, where “XX” are your initials.
- Add the following methods to either the code for this form or a separate XXValidation class:
- XXCapitalize – this takes a string parameter and returns a string. It should convert an incoming null string to an empty one, trim it of leading & trailing spaces, shift it to lower case and then capitalise each word in the string. Beware of 1-letter words.
- XXPostalCodeValidation – this takes a string and returns a Boolean. If the incoming string is null or an empty string, pass it. Otherwise, return true only if the string’s entire content fits the Canadian postal pattern “A2A 2A2” … accept upper or lower case and with or without the single space.
- XXPhoneNumberValidation – this takes a string and returns a Boolean. If the incoming string is null or empty, pass it. Otherwise, return true only if the entire string fits the phone pattern 123-123-1234, with or without the dashes.
- XXIsNumeric – this takes a string and returns a Boolean. If the incoming string is null or empty, return false. Return true only if the string contains a number defined as: at least one digit, an optional leading dash and an optional single decimal place anywhere in the number.
- Pre-Fill” loads the form with data … making it easier to test individual edits
- “Submit” edits and reformats the fields (back onto the form).
- All validation errors are displayed at once in a red label on the form or in a message box … one line per error, focus to first field in error.
- “Close” closes the form.
- 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 to first field in error.
- The member’s first name and last name are required and cannot be just blanks.
- If an email is provided, the postal information (street address, city and postal code) is optional. If email is not provided, the postal information is required. All four are fine, but not mandatory.
- The province code, if provided, must be exactly two letters, not just two characters. Accept upper- and lower-case.
- Use your XXPostalCodeValidation method to verify the postal code.
- Use your XXPhoneNumberValidation method to verify the phone number.
- 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.
- Use your XXIsNumeric method to verify the fee, then ensure it is not less than zero.
- Perform the following data conversions
- Use your XXCapitalize method to capitalise the member’s and spouse’s names, the street address, and the city.
- Derive Full Name from the member’s and spouse’s names (after capitalization). Consider these examples for Shania Twain and Russell Crowe:
- If there’s no spouse, it’s the member’s last and first names, with a comma:
- If the spouse’s last name is not provided or is the same as the member’s:
Twain, Shania & Russell
- If the spouse’s last name is different:
Twain, Shania & Crowe, Russell
- Shift the province code to upper case.
- Shift the postal code to upper case and insert a single space if there isn’t one already.
- Insert the dashes into the phone number, if they are not there already.
- Shift the email to lower case (easier to use for comparisons).
- Display the fee with two decimal places … rounded, if necessary … no commas or currency symbols.
- Zip and upload your project folder to the assignment 2 drop-box for this course.
- Hand the marking sheet in during class or in the drop-box on your teacher’s office door.