JavaScript III ECT 270 Robin Burke. Outline Validation examples password more complex Form validation Regular expressions.

Slides:



Advertisements
Similar presentations
Session 3BBK P1 ModuleApril 2010 : [#] Regular Expressions.
Advertisements

BBK P1 Module2010/11 : [‹#›] Regular Expressions.
2-1. Today’s Lecture Review Chapter 4 Go over exercises.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
Data Manipulation & Regular Expressions CSCI 215.
PERL Part 3 1.Subroutines 2.Pattern matching and regular expressions.
CS 330 Programming Languages 10 / 10 / 2006 Instructor: Michael Eckmann.
Using regular expressions Search for a single occurrence of a specific string. Search for all occurrences of a string. Approximate string matching.
Scripting Languages Chapter 8 More About Regular Expressions.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
XML Validation I DTDs Robin Burke ECT 360 Winter 2004.
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.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
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’
PHP Workshop ‹#› Data Manipulation & Regex. PHP Workshop ‹#› What..? Often in PHP we have to get data from files, or maybe through forms from a user.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Strings in PHP Working with Text in PHP Strings and String Functions Mario Peshev Technical Trainer Software University
1 CSC 594 Topics in AI – Text Mining and Analytics Fall 2015/16 4. Document Search and Regular Expressions.
Regular Expressions.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
 2003 Jeremy D. Frens. All Rights Reserved. Calvin CollegeDept of Computer Science(1/8) Regular Expressions in Java Joel Adams and Jeremy Frens Calvin.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
 2002 Prentice Hall. All rights reserved. 1 Chapter 13 – String Manipulation and Regular Expressions Outline 13.1 Introduction 13.2 Fundamentals of Characters.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming regular expressions.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company ASP.NET Validation Control Presented By : Muhammad Atif Hussain Deputy.
Appendix A: Regular Expressions It’s All Greek to Me.
12. Regular Expressions. 2 Motto: I don't play accurately-any one can play accurately- but I play with wonderful expression. As far as the piano is concerned,
©Brooks/Cole, 2001 Chapter 9 Regular Expressions.
JavaScript III ECT 270 Robin Burke. Outline Form validation Regular expressions DOM JS document model review W3C DOM Cross-browser scripting Style.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
1 Validating user input is the bane of every software developer’s existence. When you are developing cross-browser web applications (IE4+ and NS4+) this.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
JavaScript Loops. Looping Want to be able to do things more than once Basic: for (var i=initial; while-clause; increment) { statement; }
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 13.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
Strings Robin Burke IT 130. Outline Objects Strings methods properties Basic methods Form validation.
May 2006CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
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.
Regular Expressions Copyright Doug Maxwell (
Regular Expressions 'RegEx'.
Looking for Patterns - Finding them with Regular Expressions
Lecture 19 Strings and Regular Expressions
CSC 594 Topics in AI – Natural Language Processing
Regular Expressions in Perl
Regular Expressions and perl
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 ©
CSC 594 Topics in AI – Natural Language Processing
SAS in Data Cleaning.
Data Manipulation & Regex
REGEX.
Presentation transcript:

JavaScript III ECT 270 Robin Burke

Outline Validation examples password more complex Form validation Regular expressions

Examples

Regular expressions Form validation so far legal values not empty equality What if I want something more? valid address integer ssn

What we need A way to specify a pattern match the pattern against the input Solution regular expressions a syntax for expressing textual patterns

Pattern components Characters ordinary characters = themselves Special characters \ | () [ { ^ $ * + ?. to use "escape" with backslash Example \$ matches any string containing a dollar matches any string contains an "at" sign

Pattern components, cont'd Character classes \d = any digit \w = any word character, alphanumeric \s = any whitespace character. = any character Example \w\w\w\d matches foo5 but not fo5

Pattern components cont'd Alternatives [ ] = any of the characters inside ranges OK | = any of the expressions joined Examples [A-Z] matches any uppercase letter [A-Z]|[0-9] matches any uppercase letter or a digit same as [A-Z]|\d

Pattern components cont'd Repetition ? = 0 or 1 occurrences * = 0..n occurrences + = 1..n occurrences {i} = i occurrences {i,j} = between i and j occurrences Examples (0\.)?\d* matches 0.45 and 45 \d{3}-\d{2}-\d{4} matches SSN pattern \d{3}-?\d{2}-?\d{4} matches even if dashes left out

Javascript implementation Regular expression is created with / / delimiters re = /\d*/ Match function str.match (/exp/) value.match (/\d*/) usually in an if statement Can also create a RegExp object re = new RegExp ("\d*") value.match (re) Actually this doesn't work \ must be protected from JS string handling re = new RegExp ("\\d*")

Example General pattern tester Validate a form containing a cash quantity

Problem (0\.)?\d+ matches qq55mmm 1q1q1q1q We might want to ensure the position of the match

More pattern components Positioning ^ = beginning must be the first thing in the pattern $ = end must be the end of the pattern Examples ^#.* matches a line whose first character is # ^(0\.)?\d+ matches 0.45 and 45, but not b45 ^(0\.)?\d+$ matches 0.45 and 45, but not b45 or 45b

Validating Many possible patterns 9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA- Z]{2,}))$/

There's more... Extraction of matched substrings Matching against previous matches in a string Substitutions etc.

Summary Regular expressions allow for complex patterns to be written succinctly allow form validation to depend on data format Regular expressions can be dense and difficult to read can be difficult to debug require thorough documentation