subject

In this exercise, you will create a script that validates whether a credit card number contains only integers. The script will remove dashes and spaces from the string. After the dashes and spaces are removed, the script should reject the credit card number if it contains any other non-numeric characters. Complete the steps below: 1. Open Notepad++ and create a new document.
2. Type the declaration, element, header information, and
element. Use the strict DTD and "Validate Credit Card" as the content of the
element.
3. Add the following text and elements to the document body:
Validate Credit Card
4. Add the following script section to the document body:
>
5. Declare a $CreditCard array that contains three values: an empty string, a valid
credit card number with numbers and dashes, and a credit card number with four initial
uppercase letter Os.
$CreditCard = array(
"",
"8910-1234-5678-6543",
"-9123-4567-0123");
6. Add the following statements to iterate through each of the elements in the $CreditCard array to determine if the element contains a value.
foreach ($CreditCard as $CardNumber) {
if (empty($CardNumber))
echo "This Credit Card Number is
invalid because it contains an empty string. ";
7. Add the following else clause to validate the credit card number. The code uses
str_replace() functions to remove any dashes and spaces in the number. Then, a
nested if...else statement checks whether the new value is numeric. If the number
is not numeric, a warning is displayed. If the number is numeric, the modified credit card
number is displayed in the Web browser.
else {
$CreditCardNumber = $CardNumber;
$CreditCardNumber = str_replace("-", "",
$CreditCardNumber);
$CreditCardNumber = str_replace(" ", "",
$CreditCardNumber);
if (!is_numeric($CreditCardNumber))
echo "Credit Card Number " .
$CreditCardNumber . " is not a valid Credit Card
number because it contains a non-numeric character.
"
else
echo "Credit Card Number " .
$CreditCardNumber . " is a valid Credit Card
number. ";
}
}
8. Save the document as ValidCreditCardLastname. php (Lastname should be your last
name) in the Projects directory for Chapter 3. Open it in your Web browser to see how it
renders. Test the script to see if it displays a message for an empty string, strips dashes
and spaces from the credit card numbers, and identifies which credit card numbers are
valid.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:30
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. centurion: a commander in the army of ancient rome. keyword: picture:
Answers: 2
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 1
question
Computers and Technology, 23.06.2019 18:00
Which finger presses the h key on the keyboard? index finger on the left hand pinky finger on the right hand index finger on the right hand thumb on the left hand
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
You know the right answer?
In this exercise, you will create a script that validates whether a credit card number contains only...
Questions
question
Mathematics, 28.05.2021 19:50
question
Biology, 28.05.2021 19:50
question
Mathematics, 28.05.2021 19:50
question
Mathematics, 28.05.2021 19:50
Questions on the website: 13722360