Working with Forms and Regular Expressions Validating a Web Form with JavaScript.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Searching using regular expressions. A regular expression is also a ‘special text string’ for describing a search pattern. Regular expressions define.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Tutorial 6 Creating a Web Form
ISBN Chapter 6 Data Types Character Strings Pattern Matching.
CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang
Tutorial 11 Working with Operators and Expressions
Tutorial 14 Working with Forms and Regular Expressions.
JavaScript, Third Edition
Introduction to regular expression. Wéber André Objective of the training Scope of the course  We will present what are “regular expressions”
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Last Updated March 2006 Slide 1 Regular Expressions.
Regular Expressions Week 07 TCNJ Web 2 Jean Chu. Regular Expressions Regular Expressions are a powerful way to validate and format text strings that may.
Tutorial 14 Working with Forms and Regular Expressions.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
 Text Manipulation and Data Collection. General Programming Practice Find a string within a text Find a string ‘man’ from a ‘A successful man’
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
JavaScript, Fourth Edition
Introduction to Computing Using Python Regular expressions Suppose we need to find all addresses in a web page How do we recognize addresses?
CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.
Chapter 8 Cookies And Security JavaScript, Third Edition.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
1 CSC 594 Topics in AI – Text Mining and Analytics Fall 2015/16 4. Document Search and Regular Expressions.
Regular Expressions.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
JavaScript, Part 2 Instructor: Charles Moen CSCI/CINF 4230.
©Brooks/Cole, 2001 Chapter 9 Regular Expressions ( 정규수식 )
การสคริปท์ฝั่งลูกข่ายด้วย JavaScript การเขียนโปรแกรมเว็บ.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
JavaScript III ECT 270 Robin Burke. Outline Validation examples password more complex Form validation Regular expressions.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
#N14 Pattern Value (aka Substring attribute) SDD 1.1 Initial Discussion XXX = [Proposal | Initial Discussion | General Direction Proposal]
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
Tutorial 6 Creating a Web Form
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
Chapter 6 JavaScript: Introduction to Scripting
Looking for Patterns - Finding them with Regular Expressions
Tutorial 10 Programming with JavaScript
CSC 594 Topics in AI – Natural Language Processing
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Introduction to Scripting
Section 3.2c Strings and Method Signatures
CSC 594 Topics in AI – Natural Language Processing
Working with Forms and Regular Expressions
Functions, Regular expressions and Events
Web DB Programming: PHP
Regular Expressions
Introduction to Computer Science
Exam Prep.
CIS 136 Building Mobile Apps
REGEX.
What We Want To Do User enters: Mary Smith
Presentation transcript:

Working with Forms and Regular Expressions Validating a Web Form with JavaScript

Introducing Regular Expressions A regular expression is a text string that defines a character pattern One use of regular expressions is pattern- matching, in which a text string is tested to see whether it matches the pattern defined by a regular expression

Introducing Regular Expressions Creating a regular expression –You create a regular expression in JavaScript using the command re = /pattern/; –This syntax for creating regular expressions is sometimes referred to as a regular expression literal

Introducing Regular Expressions Matching a substring –The most basic regular expression consists of a substring that you want to locate in the test string –The regular expression to match the first occurrence of a substring is /chars/

Introducing Regular Expressions Setting regular expression flags –To make a regular expression not sensitive to case, use the regular expression literal /pattern/i –To allow a global search for all matches in a test string, use the regular expression literal /pattern/g

Introducing Regular Expressions Defining character positions

Introducing Regular Expressions Defining character positions

Introducing Regular Expressions Defining character positions –Can specify a collection of characters known a character class to limit the regular expression to only a select group of characters

Introducing Regular Expressions Defining character positions

Introducing Regular Expressions Repeating characters

Introducing Regular Expressions Escape Sequences –An escape sequence is a special command inside a text string that tells the JavaScript interpreter not to interpret what follows as a character –The character which indicates an escape sequence in a regular expression is the backslash character \

Introducing Regular Expressions Escape Sequences

Introducing Regular Expressions Alternating Patterns and Grouping

Introducing Regular Expressions The regular expression object constructor –To create a regular expression object re = new RegExp(pattern, flags) –re is the regular expression object, pattern is a text string of the regular expression pattern, and flags is a text string of the regular expression flags

Working with the Regular Expression Object Regular Expression methods

Working with the Regular Expression Object Validating a post code

Passing Data from a Form Appending data to a URL –Text strings can be appended to any URL by adding the ? character to the Web address followed by the text string Go to form2 –One property of the location object is the location.search property, which contains the text of any data appended to the URL, including the ? character

Passing Data from a Form Appending data to a URL –There are several limitations to the technique of appending data to a URL –URLs are limited in their length –Characters other than letters and numbers cannot be passed in the URL without modification –Because URLs cannot contain blank spaces, for example, a blank space is converted to the character code %20

Passing Data from a Form Appending and retrieving form data –Can use the technique of appending data to the URL with Web forms, too –Do this by setting a form’s action attribute to the URL of the page to which you want to pass the data, and setting the method of the form to “get”

Passing Data from a Form Appending and retrieving form data –Use the location.search property and the slice() method to extract only the text string of the field names and values –Use the unescape() function to remove any escape sequences characters from the text string –Convert each occurrence of the + symbol to a blank space –Split the text string at every occurrence of a = or & character, storing the substrings into an array