Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 330 Class 7 Comments on Exam Programming plan for today:

Similar presentations


Presentation on theme: "CS 330 Class 7 Comments on Exam Programming plan for today:"— Presentation transcript:

1 CS 330 Class 7 Comments on Exam Programming plan for today:
What is happening in GetDay? GetMonth? GetYear? What can you learn from p ? Programming plan for today: Review approaches to form validation Regular expressions Form validation with regular expressions Beginnings of CGI

2 Form Validation How can we identify a valid zip?
length = 5 all digits. Valid phone number (xxx-xxxx): A bit harder: Check each position for 3 digits, one dash, 4 digits Valid must contain must contain ‘.’ comes before ‘.’ Extension should be com, org, gov, net, mil See guestans.htm Did you use any ideas from the text? What did they do?

3 Regular Expressions An object that describes a pattern of characters.
Specified by including it within / and / var pattern = / \d{2,4}/ \d = digit, {2,4} = 2 - 4 Character classes . anything except newline \d any digit \s any whitespace \w any letter or digit [abc] a, b, or c [^abc] anything but a, b, or c [A-Za-z] any letter [0-9] same as \d red | blue red or blue Example: a letter followed by a digit: /[A-Za-z] \d / Regular expressions pop up in a number of places - unix scripts, perl cgi programs, and now javascript. An efficient way to specify patterns. Example - Kyle had to look through 1000 files and find the version numbers and date contained in comments

4 Regular Expressions Repetition:
{n, m} at least n but no more than m ? or 1 occurrences one or more * zero or more Example: 7 digit telephone: / \d{3} - \d {4} / Specifying match position ^ the beginning of the string $ the end start with capital, end with period: /^[A-Z] \.$] Exercises to do now: a pattern that contains a word with an optional period a pattern that contains Fred with a space (not Freddy) a url of the form aurora.wells.edu We are thinking locally

5 Regular Expressions Methods for testing if a pattern is present. e.g.
thePattern = /d{5}/; theZip = “12212”; Using match (a String method with RegExpr parameter): theZip.match(thePattern) is true if theZip contains pattern if (theZip.match(aPattern)) … Using test (a RegExpr method with String parameter): aPattern.test(theZip) is true if aString contains pattern if (pattern.test(theZip)) Is this enough to check a zipcode? How about zip+4? Won’t cover other methods search, replace, and split for RegExpr, and exec for String.. A name of the form John Q. Smith with optional middle initial /[A-Z] [a-z]* ([A-Z] \.)? [A-Z] [a-z]* / A name of the form Smith, J. /[A-Z] [a-z]* , \s [A-Z] \./

6 Introduction to CGI Common gateway interface References: CS 330 page
CGI allows interactions among client browser, web server, and traditional applications. E.g. Processing forms Gateways (to services not immediately available to the client, e.g. a database) Virtual documents (tailored to the user’s input, e.g. results from Yahoo) CGI programs are run on the server Results are often sent back in a client page Next two slides review standard client/server communication and CGI functioning

7 Client/Server Communication
(1) Server (3) (2) client program server program (4) (5) Steps: (1) Client program makes connection to server program (2) Client sends HTTP request message (3) Server processes HTTP request message (4) Server sends HTTP response message (5) Server closes the connection HTTP is the protocol for web communication HTTP requests HTTP headers for HTML documents (HTML is the format in which a browser can recognize a formatted document)

8 CGI Communication Server Machine (1) Client (5) Server SW (2) (4)
Other servers CGI Script (3) Other programs (1) Server SW decodes client HTTP request (2) Server SW sets variables and executes CGI script (3) CGI script runs (4) Script returns output with CGI headers to server SW (5) Server translates output and headers into HTTP response to client CGI can return graphics, text, headers tell which. Ours: CGI will return an HTML doc. Server adds HTTP headers.

9 Languages for CGI Scripts
UNIX shell commands C, C++ Perl (practical extraction and report language) Visual Basic Why Perl? Portable Powerful string manipulation operations C-like syntax

10 CGI With No Parameters hello.htm invokes script hello.cgi via
<a> ref=" Hello World</a> This generates HTTP header: GET ../scripts/hello.cgi Server executes script and sends output to client the print statements create an HTML document which is interpreted by the browser Conventions: scripts are usually stored in a separate directory and must have execute permission the first line indicates the language the second is part of the returned HTTP header

11 Next How do we write programs that accept and use information from the client?


Download ppt "CS 330 Class 7 Comments on Exam Programming plan for today:"

Similar presentations


Ads by Google