Question

Create an XHTML form that collects a name, address, phone number, and zip code. The phone number must be input in the format of ddd-ddd-dddd and the zip code must be in the format of ddddd-dddd. Write a PHP script that checks the submitted information and verifies the format of the phone number and zip code. If the information correctly matches the format, display the information contained in the submitted form. If the data does not match the required format, return an error message exampling the format problem.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

$zip = $_POST["userZip"];
$phone = $_POST["userPhone"];
// preg_match(format, data) = 1 if data matches the format = 0 if not.
$match1 = preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $phone);
$match2 = preg_match("/^[0-9]{5}-[0-9]{4}$/", $zip);

if ( $match1==0 || $match2==0 ) {
print("<p>You did not enter a phone number or zip-code in a requested format.</p>");
}
else {
$name = $_POST["userName"];
$address = $_POST["userAddress"];
$city = $_POST["userCity"];...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats