HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 17. FORMS AND INPUTS 182


17.7 Advanced Concepts


17.7.1 Input Patterns


It is possible to specify a pattern for what the user is allowed to type into
an input field.


For example, if you wanted to force the user to type a five-digit number, like
for a US zip code, you could say:


<input ... pattern=[0-9]{5} ...>


The[0-9]part means a character in the range of zero through nine.


The{5}part means five of them.


For a ten-digit telephone number using the xxx-xxx-xxxx format you could
say:


<input ... pattern=[0-9]{3}-[0-9]{3}-[0-9]{4} ...>


Patterns use something called a “regular expression.” The rules for patterns
are not difficult to learn, and are very powerful, but we will not cover them
here. You can find more on the web. Just do a Google search for “regular
expression tutorial” or “html5 pattern tutorial”.


Using a pattern does not guarantee that the browser will enforce it, but
most modern browsers do.


17.7.2 CGI: The Common Gateway Interface


HTML is the language that browsers understand. It tells them the content
of the webpage that they will present to the user.


Static HTML is the same every time it is presented. To change it, someone
must change the page that is saved on the server.


But servers can do more than simply serve up the same content every time.
Servers can run programs.


CGI, the Common Gateway Interface, is based on that idea. Instead of
finding a file to send back to the browser, we find a program to run. That
program is called a CGI program. When it runs, it creates the webpage
for the user. The server receives the webpage from the CGI program. The
server hands it back to the browser. The browser renders it for the user.

Free download pdf