COP 2500 Spring 2012
Lab #10: String Validation
Email your instructor showing what you have completed. You can get partial credit even if not fully completed with the lab.|
The goal of this assignment is to allow you to become familiar with string validation. Review the previous lab introducing strings.
Validating input is essential to administrating an account system for a website. If your account system requires a valid email address and sufficiently complex password (for security purposes), it is better to check the input first to see if it meets expectations than wait for an error to occur.
Hint: One way to check if a type of character exists in a string is to have a string containing all characters of that type, then using indexOf to search for that letter.
Part 1: Email
An email typically looks like _____@_____.com, but the extension could also be .gov, .org, .edu as well as extensions indicating other countries such as .uk or .ca. For our purposes, we will only check if there are
Notify the user (with alert or document.write) if the email is invalid.
- 2 or 3 characters after the last period in the string.
- A single @ in the string.
Part 2: Password
Password complexity is essential to security as more permitted characters and increasing the length of passwords make them harder to guess. We will only check if there are
Note: toUpperCase() and toLowerCase() will transform numbers and special characters.
- At least one lowercase character
- At least one uppercase character
- At least one number
- At least one special character (!,@,#,$,%,^,&,*,~)
Notify the user (with alert or document.write) if the password is invalid.