Simple character validation.
Select the button below to open the C# program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.
Watch this video to learn about the new concepts shown in the program:
The new commands used in this program and others that may be useful. Select them below to learn more:
x is assigned to be the number of characters in string. Can also be used to return the number of items in a list.
Returns true if character x is in upper case or false if not.
Returns true if character x is in lower case or false if not.
Returns true if character x is an alphabet letter a-z or A-Z.
Returns true if character x is a digit 0-9.
Returns true if character x is a letter (a-z or A-Z), or a digit (0-9).
Returns the string x in lowercase.
Returns the string x in uppercase.
Questions to think about with this program to check your understanding:
Identify the Boolean variable used to flag if a character is not a number.
`valid` is a Boolean variable used to flag if a character is not a number.
Explain the difference between the data types used for `number_on_card` and `character`.
`number_on_card` is a string. A string contains none, one or more characters. `character` is a character data type, known as a char in C#. The char data type can only hold zero or one character. A string is like an array of characters.
Change the program so that it:
Enter the name on the card: john smith
Enter the 16 digit number: 1234 1234 1234 1234
JOHN SMITH
Card details valid.
Enter the name on the card: invalidname2342
Enter the name on the card: j@hn sm!th
Enter the name on the card: john smith
Enter the 16 digit number: 1234 1234 1234 1234
JOHN SMITH
Card details valid.
Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.
Run your code to check that your program has met the success criteria and produces the required output.
Enter the name on the card: Cra1g Sargent
Enter the name on the card: Craig Sargent
Enter the 16 digit number: 5555666677778888
CRAIG SARGENT
Card details valid.
Enter the name on the card: D@ve Hillyard
Enter the name on the card: Dave Hillyard
Enter the 16 digit number: 1111 2222 3333 4444 5555 6666
Enter the 16 digit number: 1111222233334444555f
Enter the 16 digit number: 11112222333344445555
Enter the 16 digit number: 111122223333444f
Enter the 16 digit number: 1111222233334444
DAVE HILLYARD
Card details valid.