Regular Expressions: Form Validation

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

One common use of regular expressions is for form validation. Using regular expressions, we can check to ensure that password use the correct characters, that email addresses contain domain information, and more. In this learning activity, we’ll create various regular expressions to validate a number of fields in a registration form, making sure our front-end users can create accounts.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set the regex expression for the name value.

Define a regular expression for the name_val.

Set the regex expression for the email value.

Define an email_var regular expression.

Set the regex expression for the username value

Define the regular expression for the username_val variable.

Set the regex for the password value.

Set password_val to an appropriate regular expression.

Set the regex for the credit card value.

Set credit_val to a regular expression to match a credit card.

Additional Resources

The company you work for, EtherCloud, needs a new login page! A demo has been developed, but the regular expressions needed for the validation to work are proving to be troublesome. You've now been tasked with developing the expressions for the necessary registration fields. The requirements are as follows:

  • The name field can contain any A-Z character, case insensitive, dashes, and spaces. At least one space is required to check for a first name, last name setup. No digits.

  • The email must begin with a word character, and can contain word characters, dots, dashes, underscores in the username. The domain name must start with a word-character, but can also contain dashes, and the top-level domain must be 2 - 63 characters long, containing A-Z characters or dots

  • The username should be between 4-15 characters, and can contain alphanumeric characters, underscores, dashes, and dots.

  • The password must be between 8-30 characters and contain uppercase and lowercase letters, at least one digit, and at least one of any of these symbols: !@#$%^&*()

  • The credit card can contain digits and must be between 13-16 characters

Edit the /var/www/html/index.html file to update the *_val variables to contain the appropriate regex.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?