DACS3203                                                                    Lab08-Input Valida7on
Task 1
Please write your answers for the questions below using a different color or highlighting for ease
of grading.
1. Run the code given above and test it with the email addresses given below. If any of them is
   invalid, explain why?
   Salem.salam@udst.com valid
   ahmad-hamada@example.com          valid
   khaled-._khaldi@sales.comp-any.academy invalid
   hamed.hameed@sub-domain.my_company.com invalid
   jameel/jamal@-company.com         invalid
       •   Makes sure username (before @) contains letters, numbers, underscores, hyphens, or
           dots.
       •   Domain name (following @) contains letters, numbers, underscores, or hyphens.
       •   Top-Level Domain (TLD) must be 2 to 4 characters.
2. Although most top-level domains are usually 2-3 characters long, the maximum length of a
   TLD nowadays is 63 characters. Change the regular expression used in the code to validate the
   email address to accept such length. Write the new regex below after testing it.
       •   This allows TLDs of a maximum of 63 characters
3. Change the regex used in the code so that it doesn't match email addresses with subdomains.
   For example, user@subdomain.domain.tld should not be a valid email address. Write the new
   regex below after testing it.
       •   This ensures there’s only one dot (.) in the domain.
                                                                                  Page 1|7
DACS3203                                                                    Lab08-Input Valida7on
4. Create a method in the code that asks the user to enter a username and uses a regex to validate
   it. The username cannot contain a space, but it may contain only lowercase letters, a hyphen,
   and an underscore. The minimum length is 2 characters, and the maximum is 10 characters.
   Add your regex below after testing it in the code.
       •   Allowed: a-z, -, _
       •   Length:2to10characters
       •   No spaces allowed
5. Credit card numbers have 16 digits, every four digits must be separated by either a hyphen or
   a space (e.g. 4444-5555-6666-7777 or 4444 5555 6666 7777). However, a credit card number
                                                                                 Page 2|7
DACS3203                                                                   Lab08-Input Valida7on
   that has a mixture of separators is invalid (e.g. 4444-5555 6666 7777). Create a method that
   asks the user to input a credit card number and uses a regex to validate it. Add your regex
   below after testing it in the code.
       • 16digits
       • Grouped in 4 groups of 4 digits.
       • Allowed separators: Hyphen(-)or space().
       • Mixing separators is NOT allowed.
6. Qatari phone numbers can be written using one of the following international formats:
   +974nnnnnnnn
   00974nnnnnnnn
   (974)nnnnnnnn
   Create a method that asks the user to input a Qatari phone number and uses a regex to validate
   it. Add your regex below after testing it in the code.
       •   Valid Formats:
           o +974nnnnnnnn
           o 00974nnnnnnnn
           o (974)nnnnnnnn
                                                                                 Page 3|7
DACS3203                                                                   Lab08-Input Valida7on
7. Create a method that asks the user to input a date and validate it. The date can be entered in
   one of the following formats only:
   dd-mm-yyyy
   dd/mm/yyyy
   dd-mm-yy
   dd/mm/yy
   Add your regex below after testing it in the code.
       •   Valid Formats:
           o dd-mm-yyyy
           o dd/mm/yyyy
           o dd-mm-yy
           o dd/mm/yy
                                                                                 Page 4|7
DACS3203                                                                       Lab08-Input Valida7on
8. Create a method that asks the user to input a string. Use a regex to validate the string so that it
   will be invalid if it contains any of the tags <script> or </script>. Add your regex below after
   testing it in the code.
•   To prevent XSS attacks, block:
           a. Case-Insensitive (Blocks <script> and <SCRIPT>).
           b. Prevents XSS attacks.
                                                                                     Page 5|7
DACS3203                                                                Lab08-Input Valida7on
Submission
1. Submit this document after adding your answers and your modified java source code file. Do
   not zip the files.
                                                                              Page 6|7
DACS3203   Lab08-Input Valida7on
                Page 7|7