Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Regular Expressions 2005.pdf
Скачиваний:
95
Добавлен:
17.08.2013
Размер:
25.42 Mб
Скачать

Chapter 18

In Step 6, save the query as Titles NOT beginning A to D.

In all later steps where a reference is made to Titles beginning A to D, substitute the new query.

Figure 18-20 shows the appearance after the new query Titles NOT beginning A to D is run.

Figure 18-20

Exercises

1.Specify the SQL for a query that will find names such as Burns and Barns anywhere in the ItemAuthor field of the dBeachPurchases database.

2.Specify a query that will display the ItemTitle and ItemAuthor fields when the ItemTitle field contains the surname McDonald or MacDonald.

428

19

Regular Expressions in

JScript and JavaScript

JavaScript and JScript are both dialects of ECMAScript, the official standard (ECMA 262), which is the successor to the original proprietary Netscape JavaScript.

Netscape and Mozilla browsers use JavaScript (currently at version 1.5), and Microsoft Internet Explorer uses JScript (currently at version 5.6). Most of the functionality in each language is also present in the other dialect. Both languages provide significant regular expression functionality, which can be used in a Web browser. There are, however, some differences between the two ECMAScript dialects. This chapter focuses on functionality that is common to both dialects. In addition, there are differences between the object models supported by the Internet Explorer browser and the Mozilla family of browsers, including the Firefox browser.

To run JScript and JavaScript code, you need to have an associated host to interpret the code. When JScript and JavaScript are run in a Web browser, the browser’s JScript/JavaScript interpreter runs the scripting code. When run on the server side, JScript code can be run by Active Server Pages (ASP). In addition, JScript code can be run in association with the interpreter in the Windows Script Host (WSH).

JScript and JavaScript are often used to validate data entered into a form on a Web page. Clientside validation of forms data is much faster than server-side validation, and the responsiveness of well-written client-side code gives a significantly better user experience than the older technique of validation, which was carried out only on the server side. Typically, in modern forms scripts, there is server-side validation and processing code to complement the client-side validation scripts. This duplication of validation code has development costs associated with it and also imposes an extra maintenance task to ensure that the client-side code and the server-side code are not in conflict.

The W3C has created a specification for XForms that uses XML-based validation to provide a newer validation technique for forms data. XForms uses W3C XML Schema for validation. At the time of this writing, XForms is used much less than client-side JavaScript or JScript code.

Chapter 19

In this chapter, you will learn the following:

How to use regular expressions in JavaScript and JScript

The metacharacters supported in JavaScript and JScript

How to use the metacharacters in Web-page examples

The examples shown in this chapter have been tested in Internet Explorer 6.0 and Mozilla Firefox 0.9.3, as appropriate. Due to the differences in the supported object model, not all code will run in Firefox 0.9.3.

JScript is not the same language as JScript.NET. The latter language uses the Microsoft .NET Framework, not a JavaScript/JScript interpreter. JScript .NET is not covered in this chapter.

Using Regular Expressions in JavaScript

and JScript

One of the principal uses of JScript and JavaScript regular expressions is in processing information entered by end users into Web forms.

JavaScript and JScript code is, for security reasons, typically unable to access files held on the local file system when run in a Web browser. If scripting code were able to access, read, and write to such files when run in a browser, this would pose a significant security threat when the scripting code formed part of a Web page, whose author in many situations would be unknown and might, justifiably, be untrusted. In fact, even with those restrictions on what scripting code can do, many Web browsers offer options to disallow the running of any scripting code to provide an extra layer of reassurance for users who desire it.

If you want to try out the code examples in this chapter, you will need to have JavaScript code enabled for at least some Web pages on your preferred Web browser. Instructions are given here for the configuration of two popular Web browsers, Firefox 0.9.3 and Internet Explorer 6.0.

In Firefox 0.9.3, you can check whether JavaScript is enabled by selecting Tools Options. In the left pane of the Options window, click Web Features. The screen’s appearance will then be similar to that shown in Figure 19-1.

Ensure that the Enable JavaScript check box is checked if you want to run the code for this chapter’s examples.

Internet Explorer has more finely grained security settings. The following instructions assume that you will download the example code and run it locally.

430

Regular Expressions in JScript and JavaScript

Figure 19-1

In Internet Explorer 6, choose Tools Internet Options. In the Internet Options dialog box, select the Security tab, and click the Local Intranet option in the upper part of the Security tab (see Figure 19-2).

Figure 19-2

431