This matches a date in the MM/DD/YYYY format in the years 2011 2019. The date must include leading zeros.



Similar documents
Shasta College SharePoint Tutorial. Create an HTML Form

Using an external style sheet with Dreamweaver (CS6)

Web Design with Dreamweaver Lesson 4 Handout

Using Style Sheets for Consistency

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Using Microsoft Word. Working With Objects

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

<option> eggs </option> <option> cheese </option> </select> </p> </form>

A send-a-friend application with ASP Smart Mailer

Mail Merge (Microsoft Office 2010)

jquery Tutorial for Beginners: Nothing But the Goods

Sample- for evaluation purposes only. Advanced Crystal Reports. TeachUcomp, Inc.

Using Spry Widgets. In This Chapter

Installing and Sending with DocuSign for NetSuite v2.2

Intro to jquery. Web Systems 02/17/2012

Using Adobe Dreamweaver CS4 (10.0)

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

LAB MANUAL CS (22): Web Technology

The purpose of jquery is to make it much easier to use JavaScript on your website.

Example. Represent this as XML

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

3. Locate the different selections of Styles from the Home Tab, Styles Group

CSS 101. CSS CODE The code in a style sheet is made up of rules of the following types

Quosal Form Designer Training Documentation

Dreamweaver CS4 Day 2 Creating a Website using Div Tags, CSS, and Templates

Designing and Implementing Forms 34

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

MICROSOFT OUTLOOK 2010 READ, ORGANIZE, SEND AND RESPONSE S

FORMS. Introduction. Form Basics

Reading an sent with Voltage Secur . Using the Voltage Secur Zero Download Messenger (ZDM)

Microsoft Word Revising Word Documents Using Markup Tools

Internet Technologies

understand how image maps can enhance a design and make a site more interactive know how to create an image map easily with Dreamweaver

HOW TO MAKE A TABLE OF CONTENTS

Document Revision Date: August 14, Create a New Data Protection Policy in the Symantec.cloud Management Portal

CREATING A NEWSLETTER IN ADOBE DREAMWEAVER CS5 (step-by-step directions)

FORM-ORIENTED DATA ENTRY

vcenter Orchestrator Developer's Guide

TUTORIAL 4 Building a Navigation Bar with Fireworks

How to create pop-up menus

About XML in InDesign

HP LoadRunner. Software Version: Ajax TruClient Tips & Tricks

CMSC434 TUTORIAL #3 HTML CSS JavaScript Jquery Ajax + Google AppEngine Mobile WebApp HTML5

Outline of CSS: Cascading Style Sheets

General Electric Foundation Computer Center. FrontPage 2003: The Basics

MASTERTAG DEVELOPER GUIDE

2- Forms and JavaScript Course: Developing web- based applica<ons

USER MANUAL (PRO-CURO LITE, PRO & ENT) [SUPPLIED FOR VERSION 3]

Basic tutorial for Dreamweaver CS5

Word basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

JavaScript and Dreamweaver Examples

Jolly Server Getting Started Guide

How to Create an HTML Page

By Glenn Fleishman. WebSpy. Form and function

HOW TO CREATE AN HTML5 JEOPARDY- STYLE GAME IN CAPTIVATE

Create a GAME PERFORMANCE Portfolio with Microsoft Word

Microsoft Expression Web Quickstart Guide

Fireworks 3 Animation and Rollovers

ITCS QUICK REFERENCE GUIDE: EXPRESSION WEB SITE

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Using HTML5 Pack for ADOBE ILLUSTRATOR CS5

Web Development 1 A4 Project Description Web Architecture

Nintex Forms 2013 Help

Website Builder Overview

Basic Web Fullerton College

Outlook . User Guide IS TRAINING CENTER. 833 Chestnut St, Suite 600. Philadelphia, PA

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

Google Sites: Site Creation and Home Page Design

The Smart Forms Web Part allows you to quickly add new forms to SharePoint pages, here s how:

Dreamweaver Tutorials Creating a Web Contact Form

Module One: Getting Started Opening Outlook Setting Up Outlook for the First Time Understanding the Interface...

EXCEL Using Excel for Data Query & Management. Information Technology. MS Office Excel 2007 Users Guide. IT Training & Development

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Chapter 6. Formatting Text with Character Tags

Linking a script in a WordPress theme

HOW TO USE OIT VIA THE WEB

Creating tables of contents and figures in Word 2013

Web App Development Session 1 - Getting Started. Presented by Charles Armour and Ryan Knee for Coder Dojo Pensacola

Creating a table of contents quickly in Word

Opening the FTD Document Center. Double-click the FTD Document Center icon on your Windows desktop.

Chapter 19: XML. Working with XML. About XML

7 The Shopping Cart Module

How to pull content from the PMP into Core Publisher

Further web design: HTML forms

Microsoft Expression Web

Interspire Website Publisher Developer Documentation. Template Customization Guide

Microsoft Word 2010 Training

WebSphere Business Monitor

Website Login Integration

USER GUIDE MANTRA WEB EXTRACTOR.

Responsive Web Design for Teachers. Exercise: Building a Responsive Page with the Fluid Grid Layout Feature

Introduction to Microsoft Word 2003

Emdeon Office General User Guide Table of Contents. Emdeon Office. General User Guide. February 22, Page 1

How to build a blog with Adobe Muse and Business Catalyst Workbook.

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

Crop and Frame Your Photos

Company Setup 401k Tab

Transcription:

Validating the date format There are plans to adapt the jquery UI Datepicker widget for use in a jquery Mobile site. At the time of this writing, the widget was still highly experimental. When a stable version becomes available, you might prefer to use it instead of the following solution, which checks only the date format, not the validity of the date. This solution uses a complex regular expression. Copying regular expressions from printed books often leads to mistakes, so I suggest that you copy the code for the regex from reservations_date.html in ch06/complete. 1. Insert the following code inside the jquery documentready function that you created in the previous section (the change-handler script for the Select Menu widget has been omitted for brevity): Regular Expressions A regular expression or regex for short is a pattern for matching text. Regexes use a combination of literal text and characters with special meanings. For example, \w matches any alphanumeric character or an underscore. Learning how to build regexes isn t easy, but it s a skill worth acquiring if you use a lot of JavaScript or other programming languages. You ll also find regexes extremely useful in the Dreamweaver Find and Replace dialog box. For a basic introduction to regexes, see my tutorial at www.adobe. com/devnet/dreamweaver/articles/regular_ expressions_pt1.html. $( #arrival, #departure ).live( blur, Ê function(e) { This creates a jquery selector for the arrival and departure text input fields, and binds an onblur event handler to both of them. 2. Inside the new event-handler function, define a variable to hold the regex. Because of the limitations of the printed page, it s split over two lines, but it must be on a single, unbroken line in your code: var pattern = /^(1[0-2] 0[1-9])\/(3[01] Ê [12][0-9] 0[1-9])\/201[1-9]$/; This matches a date in the MM/DD/YYYY format in the years 2011 2019. The date must include leading zeros. 1

Chapter 6 Diving Deeper into jquery Mobile To match a date in the European DD/MM/YYYY format, use the following pattern instead: var pattern = /^(3[01] [12][0-9] 0[1-9])\/ Ê (1[0-2] 0[1-9])\/201[1-9]$/; To match a date in the YYYY/MM/DD format commonly used in East Asia, use this: var pattern = /^201[1-9]\/(1[0-2] 0[1-9])\/ Ê (3[01] [12][0-9] 0[1-9])$/; 3. You need to obtain the value entered by the user using $(this).val() and pass it as an argument to the JavaScript test() method, which returns true or false depending on whether the value matches the regex. If the input doesn t match, display an alert. The completed code looks like this: $( #arrival, #departure ).live( blur, function(e) { var pattern = /^(1[0-2] 0[1-9])\/(3 Ê [01] [12][0-9] 0[1-9])\/201[1-9]$/; if (!pattern.test($(this).val())) { alert( Date must be in MM/DD/YYYY Ê format with leading zeros'); The exclamation mark after the opening parenthesis of the condition is the logical NOT operator, which negates the meaning of the following expression. In other words, the condition means if the value doesn t match the pattern. Checking that all required fields have been filled in Because you can t be sure that all browsers recognize the HTML5 required attribute, it s a good idea to check that required fields aren t blank before submitting the form. 2

If any fields are missing, you can dynamically add a warning message to the form, highlight the affected fields, and prevent the form from being submitted. 1. Add the following style rule to the <style> block in the <head> of reservations.html:.invalid { background-color: rgba(255,0,0,0.1); This uses the rgba() color format to set the background color to red with 10% alpha transparency in effect, pale pink. 2. Add the following code inside the jquery documentready function at the bottom of the page: // Check required fields $( form ).live( submit, function(e) { // Initialize Boolean variable var OK = true; // Test each required field $( input[required] ).each(function() { if ($.trim($(this).val()) == ) { // If blank, set OK to false OK = false; // Style current element $(this).addclass( invalid ); if (!OK) { // Add warning if field(s) blank $( form ).before( <p id= errors > Ê Please fill in required fields. Ê </p>'); // Scroll to top of page window.scrollto(0,0); 3

Chapter 6 Diving Deeper into jquery Mobile else { // Remove warning if OK $('#errors').remove(); return OK; This binds an onsubmit event handler to the form. It must be bound to the form instead of the submit button because of the way that jquery Mobile handles form submission. The script begins by initializing a Boolean variable OK, which the event handler ultimately returns. If any required fields are blank, OK is reset to false, which prevents the form from being submitted. The each() method is applied to the attribute selector $( input[required] ). This executes the same function on each required field. The condition inside the function uses the jquery $.trim() utility method to strip leading and trailing spaces from the user input, and compares the value with an empty string. If the field is blank, OK is reset to false, and the invalid class is applied to the current element. If OK is false, the before() method prepends a warning paragraph to the form, and the page is scrolled to the top to bring the warning into view. The paragraph is given an ID so that it can be removed later if the form is submitted without errors. 3. There s just one final refinement: Add the following code inside the jquery document-ready handler: // Check required fields // Clear invalid class on focus $( input[required] ).live( focus, Ê function(e) { 4

$(this).removeclass('invalid'); This binds an onfocus event handler to the required fields to remove the invalid class when the focus moves into the field. Of course, this is needed only on required fields that were left blank when the form was submitted, but the function fails silently if the class hasn t been applied to an element. 4. Before you can test the page in Live view, you need to add data ajax to the opening <form> tag and set its value to false. 5. Activate Live view and scroll down to the Submit button without filling in any fields. Hold down the Ctrl/Command key and click Submit. The page should scroll to the top and display the warning message. The blank fields should also be highlighted in pale red (Figure 6.1). Figure 6.1 The form now warns users about required fields that have been left blank. Live view does not clear the invalid class from required fields when you give them focus. However, the fields are cleared as expected in a browser. 5