Question

The first script is validate.sh. This is a simple form validation script that will be used...

The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address. Each input must be validated, meaning that the input conforms to a certain standard. Here is the standard for this assignment:

  • The first name must start with a capital letter and contain only letters and hyphens.
  • The last name must start with a capital letter and contain only letters and hyphens.
  • The zip code must be exactly 5 digits and nothing else.
  • The email address must be a valid email address format, meaning USER@DOMAIN, where both USER and DOMAIN must be only letters, numbers, dots, underscores, and hyphens.

As the script reads each value, use regular expressions to ensure that the value matches the standard above. If a value does not match the standard, print an error message and exit immediately (don't prompt for the rest of the inputs). If all four values are validated successfully, then print a message indicating that fact. Here are some sample runs:

[user@localhost lab3]$ ./validate.sh

First name: R2-D2

First name must start with a capital letter and contain only letters and hyphens!

[user@localhost lab3]$ ./validate.sh

First name: Han

Last name: S0L0

Last name must start with a capital letter and contain only letters and hyphens!

[user@localhost lab3]$ ./validate.sh

First name: Han

Last name: Solo

Zip code: 12 parsecs

Zip code must be exactly 5 digits!

[user@localhost lab3]$ ./validate.sh

First name: Han

Last name: Solo

Zip code: 12345

Email address: han.solo

Email address must be USER@DOMAIN, where both USER and DOMAIN must be only letters, numbers, dots, underscores, and hyphens!

[user@localhost lab3]$ ./validate.sh

First name: Han

Last name: Solo

Zip code: 12345

Email address: [email protected]

Validated!

[user@localhost lab3]$

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash

count=0

read -p "Enter the first name: " fname

echo

if [[ "$fname" =~ [A-Z][A-Za-z-]+$ ]]

then

count=`expr $count + 1`

else

echo "First name must start with a capital letter and contain only letters and hyphens!"

fi

read -p "Enter the last name: " lname

echo

if [[ "$lname" =~ [A-Z][A-Za-z-]+$ ]]

then

count=`expr $count + 1`

else

echo "Last name must start with a capital letter and contain only letters and hyphens!"

fi

read -p "Enter the zip code: " zipcode

echo

if [[ "$zipcode" =~ ^[0-9][0-9][0-9][0-9][0-9]$ ]]

then

count=`expr $count + 1`

else

echo "Zip code must be exactly 5 digits!"

fi

read -p "Enter the email ID: " email

echo

if [[ "$email" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]

then

count=`expr $count + 1`

else

echo "Email address must be USER@DOMAIN, where both USER and DOMAIN must be only letters, numbers, dots, underscores, and hyphens!"

fi

if [ $count == 4 ]

then

echo "Validated!"

fi

Save this as validate.sh

Run as: bash validate.sh (or) ./validate.sh

OUTPUT:

Let me know in the comments section if you have any doubts.

Add a comment
Know the answer?
Add Answer to:
The first script is validate.sh. This is a simple form validation script that will be used...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to...

    Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to the script (see below) 2. Read the file one line at a time (i.e., for line in file--each line will be a separate email address) 3. Print (to the screen) a line that "interprets" the email address as described below 4. When finished, display the total number of email addresses and a count unique domain names Each email address will either be in the...

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

  • Write a method in java named isValidEmail that takes a string as input parameter, and returns...

    Write a method in java named isValidEmail that takes a string as input parameter, and returns true if that string represents a valid email address, or false otherwise. An email address is considered valid if it follows this format “[email protected]”, where:  user123 represents a sequence of word characters (i.e., letters, digits, or underscore) whose length is between 1 and 10 (inclusive), but the first character must be a letter  domain represents a sequence of alphanumeric characters (i.e., letters...

  • Your task for this project is to write a parser for a customer form. You need to develop a Java a...

       Your task for this project is to write a parser for a customer form. You need to develop a Java application using Parboiled library. Your program should include a grammar for the parser and display the parse tree with no errors. Remember that your fifth and sixth assignments are very similar to this project and you can benefit from them. The customer form should include the following structure: First name, middle name (optional), last name Street address, city, state (or...

  • I need help please to add function for clean up any inputs form that we receive from the users for this code below : &lt...

    I need help please to add function for clean up any inputs form that we receive from the users for this code below : <?php session_start(); // initializing variables $fname = ""; $lname = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $email = ""; $phone = ""; $errors = array(); // connect to the database $db = mysqli_connect("localhost","root","password","db"); // REGISTER USER if (isset($_POST['reg_user1'])) { // receive all input values from the form $fname =...

  • in a java application need  to create an application which prompts the user numerator and denominator values...

    in a java application need  to create an application which prompts the user numerator and denominator values then show the result of the division.  The application will use exception handling to verify the user has entered valid input and will continue to prompt the user for input as long as the value they enter is invalid.  Once the user has entered valid numerator and denominator values, the result is shown and the application exits. had some issues when I entered letters instead of...

  • The ", delimiter" should now be changed to use the "^ delimiter". There needs to be...

    The ", delimiter" should now be changed to use the "^ delimiter". There needs to be an 2nd address field added to the original code, as well as, a "plus 4" on the zip code (example: 47408-6606). Then the additional prompts must be added. Thank you! Last Real-World problem (in module 04 - 05), you added functionality to allow the user to enter multiple patients until the user indicated done. You are to enhance this functionality. Add the following functionality...

  • For the following codes, define the validation criteria (there may be multiple checks for each field)...

    For the following codes, define the validation criteria (there may be multiple checks for each field) and the order that you would test each of the conditions. a. A credit card number entered on a Web form: The customer has selected the type of credit card from a drop-down list. b. A part number in a hardware store: The part number is a complex code, where the first digit represents the department (such as housewares, automotive, and so on), and...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT