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.

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.
Using regular expressions Search for a single occurrence of a specific string. Search for all occurrences of a string. Approximate string matching.
Tutorial 14 Working with Forms and Regular Expressions.
Escaping Characters document.write(). Learning Objectives By the end of this lecture, you should be able to: – Recognize some of the characters that can.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
JavaScript, Third Edition
Scripting Languages Chapter 8 More About Regular Expressions.
Introduction to JavaScript Form Verification - Fort Collins, CO Copyright © XTR Systems, LLC Verifying Submitted Form Data with JavaScript Instructor:
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Slide 6a-1 CHAPTER 6 Matching Patterns: Using Regular expressions to match patterns.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
Regular Language & Expressions. Regular Language A regular language is one that a finite state machine (fsm) will accept. ‘Alphabet’: {a, b} ‘Rules’:
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.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
PHP : Hypertext Preprocessor
Tutorial 14 Working with Forms and Regular Expressions.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
Language Recognizer Connecting Type 3 languages and Finite State Automata Copyright © – Curt Hill.
 Text Manipulation and Data Collection. General Programming Practice Find a string within a text Find a string ‘man’ from a ‘A successful man’
1 Some Variations on Date Display 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered.
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
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.
Introduction to XML 1. XML XML started out as a standard data exchange format for the Web Yet, it has quickly become the fundamental instrument in the.
2440: 211 Interactive Web Programming Expressions & Operators.
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.
Programming Languages Meeting 13 December 2/3, 2014.
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.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Regular Expressions for PHP Adding magic to your programming. Geoffrey Dunn
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.
Copyright © 2003 Pearson Education, Inc. Slide 6a-1 The Web Wizard’s Guide to PHP by David Lash.
Introduction to JavaScript CS101 Introduction to Computing.
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 10 – JavaScript Validation Instructor: Brent Presley.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Copyright © 2003 Pearson Education, Inc. Slide 6a-1 The Web Wizard’s Guide to PHP by David Lash.
HTML5 Forms Forms are used to capture user input …
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 13.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Tutorial 11 1 JavaScript Operators and Expressions.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
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.
Finding the needle(s) in the textual haystack
Regular Expressions 'RegEx'.
CS 330 Class 7 Comments on Exam Programming plan for today:
Looking for Patterns - Finding them with Regular Expressions
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
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 ©
Finding the needle(s) in the textual haystack
Finding the needle(s) in the textual haystack
Working with Forms and Regular Expressions
Advanced Find and Replace with Regular Expressions
T. Jumana Abu Shmais – AOU - Riyadh
Today’s Objectives Week 12 Announcements ASP.NET
Data Manipulation & Regex
CIS 136 Building Mobile Apps
Presentation transcript:

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 reduce several dozens lines of code to a line or two. A regular expression (often abbreviated as RegExp) is a pattern that is written using special symbols, which describe one or more text strings. You use regular expressions to match patterns of text, so that your script can easily recognize and manipulate text. Just like comparison operators are used to evaluate numbers in mathematic expressions, operators are used to evaluate text.

JS Regular Expression For var re = ]?\w+)*(\.\w{2,3})+$/; Regular expressions always begin and end with / The ^ caret means that this expression will examine a starting at the string's beginning The \w means any one character "a" through "z", "A" through "Z", "0" through "9" or underscore The + plus means one or more of whatever the previous item was that we're checking on.

JS Regular Expression For var re = ]?\w+)*(\.\w{2,3})+$/; The opening ( signifies a group - we can refer to anything within the parenthesis as a group later. The bracket shows that we can have any one of the characters inside, in this example.- The backslash is used to escape the character. (period) The entered character may have either a period of a dash, but not both.

JS Regular Expression For var re = ]?\w+)*(\.\w{2,3})+$/; The question make means that we can have zero or one of the previous item. So along with it being ok to have either a period or dash in the first part of the (the part before sign), it's ok to have neither. The new \w+ says that the period or dot must be followed by some other characters. Closing parenthesis means that it's the end of a group.

JS Regular Expression For var re = The asterisk * means that we can have zero or more of the previous item, whatever was inside the parenthesis. So either "name" or "try-123-abc" are valid prefix. character stands for itself, located between address and domain name. The \w again means any one character "a" - "z", "A" - "Z", "0" - "9" or underscore + plus means one or more of whatever the previous item was…

JS Regular Expression For var re = Group - ([\.-]?\w+)* which says that period and dashes are allowed within the suffix of an address The final group \.\w{2,3} says that we're expecting a period followed by characters, letter, number or underscore. The numbers represent 2 or 3 of the previous item (e.g. uk or net). + means that the pervious item, in this case the group, must exist one or more times -.net or.ox.ac.uk

JS Regular Expression for URL var re = ]?\w+)*(\.\w{2,3})+$/; The regular expression ends with $ which signifies that the matched string must end here. This way an that begins properly but ends with garbage is not validated. The slash closes the regular expression and the semicolon ends the JavaScript statement.

JS Regular Expression for URL var re = /^(file|http):\/\/\S+\/\S+\.(gif|jpg|png)$/i; Check for everything within /^ and $/ Input can begin with either file or http, next characters must be :// \S+ is used to signify that one ore more non- white space characters follow.

HTML5 attern.htm attern.htm Through HTML5 new form field types and attributes to existing fields, much form processing can be handled by HTML. Pattern attributes are added to all the form fields that require validation. New attributes allow a pattern to be specified for the input field and if anything is entered in the field then the value input must match the pattern or the input is considered to be invalid and must be corrected.

jQuery Form Validation Plugin

References All Materials from Professor Ricardo Miranda 41/week04.html