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...
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.?
Create a form using the following HTML elements at a minimum. Style the form in your...
Create a form using the following HTML elements at a minimum. Style the form in your CSS. You do not need to include a form action (i.e. the form doesn't have to do anything - we're designing the front end of the form). textarea textbox input type of "email" select radio button checkbox submit button style at least three elements of your form in your stylesheet, including your submit button Use a comment to delineate the beginning and end of...
- Create an html form (bank form) and the PHP code with 2 accounts with options...
- Create an html form (bank form) and the PHP code with 2 accounts with options to transfer, deposit or withdraw money.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT