Question

In: Computer Science

Write an HTML document to provide a form that collects familynames and telephonenumbers. The...

Write an HTML document to provide a form that collects family names and telephone

numbers. The family name should start with a capital letter, followed by at least one

lowercase letter, and not include any spaces or any other characters, and the length

should not be more than 30 characters. The phone numbers must be in the format

(ddd)-ddd-dddd. Write a PHP script that checks the submitted last name and the

telephone number to be sure that they conform to the required format and then returns

a response indicating whether the format was correct. Use regular expressions to

validate the names and phone numbers.

Solutions

Expert Solution

 

I use preg_match() function in PHP for regular expression and the syntax I use explain in the code.

syntax

preg_match("regular expression",string)

Html code




PHP code

$l1=$_POST['l1'];
$p1=$_POST['p1'];
echo $l1;
echo $p1;


//^[A-Z] is for 1st character capital
//[-a-z] is for 2nd character in small letter
//([a-zA-Z]) from 3rd character to 30th character any letter in small or caps


if(!preg_match("/^[A-Z][-a-z]([a-zA-Z]){1,30}$/",$l1))
echo "Lastname Error";

// ^ starting $ is for ending

//^\( is for 1st character is first bracket (
//[0-9]{3} is for next 3 characters will be from 0-9
//- is a character
// \) is for close bracket
// [0-9]{3} is for next 3 characters will be from 0-9
// [0-9]{4} is for next 4 characters will be from 0-9
if(!preg_match("/^\([0-9]{3}\)-[0-9]{3}-[0-9]{4}$/",$p1))
echo "
Phone Error";
?>


Related Solutions

HTML document containing a form. The title bar should display “Voting Form”. The form should contain...
HTML document containing a form. The title bar should display “Voting Form”. The form should contain the following: Text boxes to accept the person’s name and e-mail address At least five radio buttons the user can use to vote for a candidate for some office. (You make up some names) Text box for write-in alternative Checkboxes with name and value attributes for these options: oThis is the first time I have voted online. o I have periodically voted online. o...
Create, test, and validate an HTML document that has a form with the following controls: a....
Create, test, and validate an HTML document that has a form with the following controls: a. A text box to collect the user's name b. Four checkboxes, one for each of the following items: i. Four 25-watt light bulbs for $2.39 ii. Eight 25-watt light bulbs for $4.29 iii. Four 25-watt long-life light bulbs for $3.95 iv. Eight 25-watt long-life light bulbs for $7.49 c. A collection of three radio buttons that are labeled as follows: i. Visa ii. Master...
What does the HTML tag designate in an HTML document?
What does the HTML tag designate in an HTML document?
lab3 exercise 5 html <!DOCTYPE html> <!-- Webpage HTML document for Lab 03.   Author: Amir H...
lab3 exercise 5 html <!DOCTYPE html> <!-- Webpage HTML document for Lab 03.   Author: Amir H Chinaei   For: EECS 1012, York University, Lassonde School of Engineering --> <html lang="En"> <head>   <meta charset="UTF-8">   <title> EECS1012: Lab 3 - My Kit </title>   <!-- in Ex1, add a link tag here to connect it to the css file -->   <link rel="stylesheet" type="text/css" href="myLearningKit_ex2.css">   <script src="myLearningKit_ex4.js"></script>      <!-- in Ex2, add a script tag here to connect it to the js file -->   ...
FOR HTML Web scripting Complete the following: Create and test an HTML document that has six...
FOR HTML Web scripting Complete the following: Create and test an HTML document that has six short paragraphs of text that describe various aspects of the state in which you live. You must define three different paragraph styles, p1, p2, and p3. The p1 style must use left and right margins of 20 pixels, a background color of pink, and a foreground color of blue. The p2 style must use left and right margins of 30 pixels, a background color...
Write a PHP program using HTML form. It will take Length, Width and Height of a...
Write a PHP program using HTML form. It will take Length, Width and Height of a box as input. When a button is pressed, it will calculate the Volume. If Volume is less than 25 then display the message “Small box”. If Volume is from 25 to 50, it will display the message “Medium box”. When the Volume is greater than 50, then display the message “Large box”.
2. The HTML document on the following page consists of JavaScript code executed when the document...
2. The HTML document on the following page consists of JavaScript code executed when the document is loaded. It prompts the user for his/her name (first and last names) then outputs the greeting “Hello Mr. _____!” or “Hello Ms. _____!” (where _____ is the user’s last name) depending on whether the first name is recognized as a male name. (In the code, only three male names are checked; a realistic program would check many more names.) We allow for the...
CSS Write a document wide style block (include the correct HTML tag) to set all <p>...
CSS Write a document wide style block (include the correct HTML tag) to set all <p> tags to be double spaced and justified (not ragged left / right text)
Assume that there is an image “fewa.jpg” in the root of the HTML folder. Write HTML...
Assume that there is an image “fewa.jpg” in the root of the HTML folder. Write HTML code to insert that image with appropriate alternative text. Also, apply an appropriate title to the image.?
Your HTML document should contain the following elements/features: HTML tags: An <input> tag labeled "Timer Duration"...
Your HTML document should contain the following elements/features: HTML tags: An <input> tag labeled "Timer Duration" with the initial value 0 A <button> tag labeled "Start" Script: When the user presses the button (1b), a function will begin that does the following: Reads the value from the input field (1a) Removes the <input> and <button> tags (1a & 1b) Creates a new <p> tag, initialized to show the input value Starts a timer that ticks down to zero. For every...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT