HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf ·...

35
29/04/2011 1 HTML 5 HTML 5 Part I Part I Introduction Introduction, , structure structure and and semantics semantics Laura Farinetti Dipartimento di Automatica e Informatica Politecnico di Torino [email protected] 1 HTML 5 HTML 5 HTML5 is the next major revision of the HTML standard, currently under development Working Draft, April 5 th 2011 Work on the specifications started in June 2004 Currently being carried out in a joint effort between the W3C HTML WG and the WHATWG (Hypertext Application Technology Working Group ) Not jet standard (until 2022?), but parts are going to be implemented by browsers 2

Transcript of HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf ·...

Page 1: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

1

HTML 5 HTML 5 –– Part IPart IIntroductionIntroduction, , structurestructure and and semanticssemantics

Laura Farinetti

Dipartimento di Automatica e Informatica

Politecnico di Torino

[email protected]

1

HTML 5HTML 5

HTML5 is the next majorrevision of the HTML standard, currently under development

◦ Working Draft, April 5th 2011

Work on the specifications started in June 2004

Currently being carried out in a joint effort between the W3C HTML WG and the WHATWG (Hypertext Application Technology Working Group )

Not jet standard (until 2022?), but parts are going to be implemented by browsers

2

Page 2: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

2

HTML 5HTML 5

“HTML5 will reach the Proposed

Recommendation stage sometime in 2022.”

◦ Ian Hickson, editor of the HTML5 specification

However, parts of specification are going

to be implemented by browsers

◦ The latest versions of Safari, Chrome, Firefox,

and Opera support some HTML5 features

◦ Internet Explorer 9 supports some HTML5

features

3

Supported featuresSupported features

4

Page 3: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

3

The HTML5 test The HTML5 test

How well does your browser support HTML5?◦ http://html5test.com/

5

Mozilla Firefox 3.6.13

Opera 11.0

The HTML5 test The HTML5 test

How well does your browser support HTML5?◦ http://html5test.com/

6

Internet Explorer 8.0

Page 4: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

4

Rough timeline of web technologiesRough timeline of web technologies

1991 HTML

1994 HTML 2

1996 CSS 1 + JavaScript

1997 HTML 4

1998 CSS 2

2000 XHTML 1

2002 Tableless Web Design

2005 AJAX

2009 HTML 5

7

HTML 5HTML 5

HTML5 ~= HTML + CSS + JS API

8

Page 5: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

5

RationaleRationale

“This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML). In this version, new features are introduced to help Web application authors, new elements are introduced based on research into prevailing authoring practices, and special attention has been given to defining clear conformance criteria for user agents in an effort to improve interoperability. This specification is intended to replace (be a new version of) what was previously the HTML4, XHTML 1.0, and DOM2 HTML specifications.”

Specifications in A4 format: 690 pages (~War and Peace by Leo Tolstoy)

9

HandHand--made code?made code?

NO

Use a framework/library...

◦ SproutCorehttp://www.sproutcore.com/

◦ Modernizrhttp://www.modernizr.com/

◦ HTML5 shivhttp://html5shiv.googlecode.com

◦ ExplorerCanvashttp://excanvas.sourceforge.net/

◦ More to come…

10

Page 6: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

6

New featuresNew features

The canvas element for drawing

The video and audio elements for media

playback

Better support for local offline storage

New content specific elements, like article,

footer, header, nav, section

New form controls, like calendar, date,

time, email, url, search

11

New elements New elements

HTML 4.01 obsolete or never used

elements are deleted or re-written

New elements for better structure,

drawing, media content, and better form

handling are included, to better reflect

today‟s internet use

12

Page 7: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

7

WhatWhat‟s ‟s newnew in HTML5in HTML5

13

WhatWhat‟s ‟s newnew in HTML5in HTML5

Many pieces of the HTML5effort (e.g. Local Storage,WebSocket, and Geolocation) were originally part of the HTML5 specification

Moved to a separate standards document to keep the specification focused

Industry still refers to the original set of features, including Web Sockets, as “HTML5”

14

Page 8: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

8

What‟s new in HTML5What‟s new in HTML5

15

Doctype

Structural elements

Web forms

DoctypeDoctype and less header codeand less header code

16

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Sample page</title>

<link rel="stylesheet" href="style-original.css" />

</head>

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0

Transitional//EN" "http://www.w3.org/1999/xhtml1-

transitional.dtd">

<html lang="en" xml:lang="en"

xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type"

content="text/html; charset="utf-8">

<title>Sample page</title>

<link rel="stylesheet" href="style-original.css"

type="text/css" />

</head>

HTML 4

HTML 5

Page 9: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

9

New tags in HTML5New tags in HTML5

17

Removed tags in HTML5Removed tags in HTML5

18

Page 10: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

10

Structural elementsStructural elements

Layout

◦ <header> <footer> <nav> <section> <article> <aside>

Inline

◦ <time> <details> <figure> <mark>

Interactive

◦ <audio> <video> <canvas>

19

Layout: more Layout: more semanticsemantic HTML HTML tagstags

20

HTML 4

Page 11: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

11

Layout: more Layout: more semanticsemantic HTML HTML tagstags

21

HTML 5

Structural elementsStructural elements

<header>

◦ A group of introductory or navigational aids

◦ Usually intended to contain the section‟s heading (an h1–h6 element or an hgroup element), but this is not required

◦ Can also be used to wrap a section‟s table of contents, a search form, or any relevant logos

<hgroup>

◦ Heading of a section: used to group a set of h1–h6 elements when the heading has multiple levels, such as subheadings, alternative titles, or taglines

<nav>

◦ Section of a page that links to other pages or to parts within the page: a section with navigation links

◦ Only sections that consist of major navigation blocks are appropriate for the nav element

22

Page 12: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

12

Structural elementsStructural elements

<article>

◦ A self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable

◦ E.g. : a forum post, a magazine or newspaper article, a blog entry, a user submitted comment, ...

<section>

◦ Generic section of a document or application

◦ Thematic grouping of content, typically with a heading

<aside>

◦ A section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content

◦ Can be used for typographical effects like pull quotes or sidebars, for advertising, for groups of nav elements, and for other content that is considered separate from the main content of the page

23

Structural elementsStructural elements <footer>

◦ A footer for its nearest ancestor sectioning content or sectioning root element

◦ Typically contains information about its section such as who wrote it, links to related documents, copyright data, …

◦ Do not necessarily have to appear at the end of a section, though they usually do

<address>

◦ The contact information for its nearest article or body element ancestor

◦ Must not be used to represent arbitrary addresses (e.g. postal addresses), unless those are in fact the relevant contact information

◦ Typically, it would be included along with other information in a footer element

24

Page 13: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

13

25

26

Page 14: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

14

Figure and figure captionFigure and figure caption

27

<figure>

<img src="bubbles-work.jpeg"

alt="Bubbles, sitting in his office chair, works

on his latest project intently.">

<figcaption>Bubbles at work</figcaption>

</figure>

<!DOCTYPE html>

<html>

<p>In <a href="#l4">listing 4</a> we see the primary

core interface API declaration.</p>

<figure id="l4">

<figcaption>Listing 4. The primary core interface

API declaration.</figcaption>

<pre><code>interface PrimaryCore {

boolean verifyDataLine();

void sendData(in sequence&lt;byte> data);

void initSelfDestruct();

}</code></pre>

</figure>

</html>

Time and publishdate attributeTime and publishdate attribute

<time datetime pubdate>

◦ Represents either a time on a 24 hour clock, or a precise date in the Gregorian calendar, optionally with a time and a timezone offset

◦ The datetime attribute, if present, gives the date or time being specified. Otherwise, the date or time is given by the element‟s contents

◦ The pubdate attribute is a boolean attribute. If specified, it indicates that the date and time given by the element is the publication date and time of the nearest ancestor article element, or, if the element has no ancestor article element, of the document as a whole

28

<time pubdate datetime="2009-10-09T14:28-08:00"></time>

Page 15: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

15

Summary: new markup elements Summary: new markup elements

29

Summary: new markup elements Summary: new markup elements

30

Page 16: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

16

Ruby annotationsRuby annotations

Short runs of text alongside the base text, typically used in East Asian documents to indicate pronunciation or to provide a short annotation

31

HTML5 formsHTML5 forms

Formerly called Web Forms 2.0

Native functionality (no scripting for validation) ◦ Means less coding

New form functionalities◦ Date and color pickers

◦ Search, e-mail, web address input types

◦ Validation

◦ Spin boxes and sliders

Backward compatible◦ Features degrade gracefully (unknown input types

are treated as text-type) input

32

Page 17: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

17

HTML5 formsHTML5 forms New input types

New elements

New attributes33

Date pickersDate pickers

New input typesNew input types

Allow for better input control and validation

If not supported, they will behave as regular text fields

34

Page 18: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

18

email input typeemail input type

The value of the email field is automatically validated when the form is submitted

35

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

E-mail: <input type="email" name="user_email" /><br />

<input type="submit" />

</form>

</body>

</html>

Si prega di inserire un indirizzo

email valido

urlurl input typeinput type

The value of the url field is automatically validated when the form is submitted

36

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Homepage: <input type="url" name="user_url" /> <br />

<input type="submit" />

</form>

</body>

</html>

Si prega di inserire un indirizzo

web valido

Page 19: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

19

number input typenumber input type

Restrictions on which numbers are accepted

37

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Points: <input type="number" name="points" min="1"

max="10" />

<input type="submit" />

</form>

</body>

</html>

Restrictions on type numberRestrictions on type number

38

<!DOCTYPE HTML>

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

<input type="number" name="points" min="0" max="10"

step="3" value="6" />

<input type="submit" />

</form>

</body>

</html>

Page 20: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

20

range input typerange input type

39

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Points: <input type="range" name="points"

min="1" max="10" />

<input type="submit" />

</form>

</body>

</html>

FirefoxFirefoxOperaOpera

Input type Input type -- date pickersdate pickers

New input types for selecting date and time

◦ date - selects date, month and year

◦ month - selects month and year

◦ week - selects week and year

◦ time - selects time (hour and minute)

◦ datetime - selects time, date, month and year (UTC time)

◦ datetime-local - selects time, date, month and year (local time)

40

Page 21: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

21

Date pickersDate pickers

41

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Date: <input type="date" name="user_date" />

<input type="submit" />

</form>

</body>

</html>

color input typecolor input type

42

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Color: <input type="color" name="user_color" />

<input type="submit" />

</form>

</body>

</html>

Page 22: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

22

New form elementsNew form elements

Browser support

43

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Webpage: <input type="url" list="url_list" name="link" />

<datalist id="url_list">

<option label="W3Schools"

value="http://www.w3schools.com" />

<option label="Google" value="http://www.google.com" />

<option label="Microsoft"

value="http://www.microsoft.com" />

</datalist>

<input type="submit" />

</form>

</body>

</html>

datalistdatalist element element

Specifies a list of options for an input field◦ To bind a datalist to an input field, the list attribute of

the input field refers to the id of the datalist

44

Page 23: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

23

keygenkeygen elementelement

Purpose: to provide a secure way to authenticate users

It is a key-pair generator

◦ When a form is submitted, two keys are generated, one private and one public

The private key is stored on the client, and the public key is sent to the server

The public key could be used to generate a client certificate to authenticate the user in the future

Currently, the browser support for this element is not good enough to be a useful security standard

45

keygenkeygen element element

46

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_keygen.asp" method="get">

Username: <input type="text" name="usr_name" />

Encryption: <keygen name="security" />

<input type="submit" />

</form>

</body>

</html>

Page 24: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

24

PublicPublic--key cryptographykey cryptography Widely used set of methods for transforming a written

message into a form that can be read only by the intended recipient

This cryptographic approach involves the use of asymmetric key algorithms

◦ The non-message information (the public key) needed to transform the message to a secure form is different from the information needed to reverse the process (the private key)

An unpredictable (typically large and random) number is used to begin generation of an acceptable pair of keys suitable for use by an asymmetric key algorithm

47

SymmetricSymmetric--keykey algorithmalgorithm

Use trivially related, often identical, cryptographic keys for both decryption and encryption

48

Page 25: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

25

PublicPublic--keykey cryptographycryptography

In an asymmetric key encryption scheme, anyone can encrypt messages using the public key, but only the holder of the paired private key can decrypt

Security depends on the secrecy of that private key

49

PublicPublic--keykey cryptographycryptography

In some related signature schemes, the private key is used to sign a message

Anyone can check the signature using the public key

50

Page 26: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

26

PublicPublic--keykey cryptographycryptography

After obtaining an authentic copy of each other‟s public keys, Alice and Bob can compute a shared secret offline

The shared secret can be used as the key for a symmetric cipher

51

<!DOCTYPE HTML>

<html><head>

<script type="text/javascript">

function resCalc()

{ numA=document.getElementById("num_a").value;

numB=document.getElementById("num_b").value;

document.getElementById("result").value=Number(numA)+

Number(numB); }

</script>

</head>

<body>

<p>Simple calculator using the output element:</p>

<form onsubmit="return false">

<input id="num_a" /> +

<input id="num_b" /> =

<output id="result" onforminput="resCalc()"></output>

</form>

</body></html>

output element output element Used for different types of output, like calculations

or script output

52

Page 27: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

27

New form attributesNew form attributes

53

New New formform attributesattributes

autocompleteattribute

54

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get" autocomplete="on">

First name:<input type="text" name="fname" /><br />

Last name: <input type="text" name="lname" /><br />

E-mail: <input type="email" name="email"

autocomplete="off" /><br />

<input type="submit" />

</form>

<p>Fill in and submit the form, then reload the page to see

how autocomplete works.</p>

<p>Notice that autocomplete is "on" for the form, but "off"

for the e-mail field.</p>

</body>

</html>

Page 28: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

28

New New formform attributesattributes

autofocus attribute

◦ specifies that a field should automatically get focus when a page is loaded

55

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

User name: <input type="text" name="user_name"

autofocus="autofocus" />

<input type="submit" />

</form>

</body>

</html>

New New formform attributesattributes

form attribute

◦ specifies one or more forms the input field belongs to

56

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get" id="user_form">

First name:<input type="text" name="fname" />

<input type="submit" />

</form>

<p>The input field below is outside the form element, but

still part of the form.</p>

Last name: <input type="text" name="lname" form="user_form" />

</body>

</html>

Page 29: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

29

New New formform attributesattributes

multiple attribute ◦ specifies that multiple values can be selected for an input

field form attribute

57

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Select images: <input type="file" name="img"

multiple="multiple" />

<input type="submit" />

</form>

<p>Try selecting more than one file when browsing for files.</p>

</body>

</html>

New New formform attributesattributes

required attribute

◦ specifies that an input field must be filled out before submitting

58

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Name: <input type="text" name="usr_name"

required="required" />

<input type="submit" />

</form>

</body>

</html>

Questo campo è obbligatorio

Page 30: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

30

New New formform attributesattributes

pattern attribute

◦ specifies a pattern used to validate an input field

◦ a pattern is a regular expression

59

<!DOCTYPE HTML>

<html>

<body>

<form action="demo_form.asp" method="get">

Country code: <input type="text" name="country_code"

pattern="[A-z]{3}" title="Three letter country code" />

<input type="submit" />

</form>

</body>

</html>

Si prega di utilizzare il formato richiesto

Three letters country code

PatternsPatterns

Regular expressions

E.g. valid e-mail address:

RFC 2822: official standard

60

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-

9!#$%&'*+/=?^_`{|}~

\

\

]*[a

9])?|

9

9

\

\

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-

9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-

\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-

\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-

]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-

9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-

9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-

9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-

\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-

\x7f])+)\])

^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$

Page 31: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

31

Regular expressionsRegular expressions

^[a-zA-Z0-9._-]+

◦ The email address must begin with alpha-numeric characters (both lowercase and uppercase characters are allowed): it may have periods, underscores and hyphens

@

◦ There must be a „@‟ symbol after initial characters

[a-zA-Z0-9.-]+

◦ After the „@‟ sign there must be some alpha-numeric characters; it can also contain period and and hyphens

\.

◦ After the second group of characters there must be a period („.‟); this is to separate domain and subdomain names.

[a-zA-Z]{2,4}$

◦ Finally, the email address must end with two to four alphabets; {2,4} indicates the minimum and maximum number of characters

61

^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$

Examples of eExamples of e--mail patternsmail patterns

62

[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+

(?:

@(?:[a

[

[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+

(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*

@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+

[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+

(?:

@(?:[a

(?:[

info|mobi|name|aero|asia|jobs|museum

[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+

(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*

@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+

(?:[a-zA-Z]{2}|com|org|net|edu|gov|mil|biz|

info|mobi|name|aero|asia|jobs|museum)\b

Page 32: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

32

Regular expression basic syntaxRegular expression basic syntax

Characters

63

Regular expression basic syntaxRegular expression basic syntax

Character classes or character sets [abc]

64

Page 33: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

33

Regular expression basic syntaxRegular expression basic syntax

Character classes or character sets [abc]

Dot

65

Regular expression basic syntaxRegular expression basic syntax

Anchors

66

Page 34: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

34

Regular expression basic syntaxRegular expression basic syntax

Word boundaries

Alternation

67

Regular expression basic syntaxRegular expression basic syntax

Quantifiers

68

Page 35: HTML 5 Part I - polito.itelite.polito.it/files/courses/01NPYPD/lucidi/04-HTML5-1.pdf · 2014-10-06 · 29/04/2011 1 HTML 5 –Part I Introduction, structure and semantics Laura Farinetti

29/04/2011

35

Regular expression basic syntaxRegular expression basic syntax

Quantifiers

69

Summary of browser Summary of browser

supportsupport Mozilla Firefox 3.6.13 Opera

70