■
CONTENTS
x
■
Chapter 9: Performing Form Validation with Regular Expressions .....................311
Getting Comfortable with Regular Expressions .............................................................311
Understanding Basic Regular Expression Syntax................................................................................. 311
Drilling Down on the Basics of Pattern Modifiers................................................................................. 316
Getting Fancy with Backreferences...................................................................................................... 318
Matching Character Classes................................................................................................................. 320
Finding Word Boundaries ..................................................................................................................... 323
Using Repetition Operators................................................................................................................... 323
Detecting the Beginning or End of a String .......................................................................................... 324
Using Alternation .................................................................................................................................. 324
Using Optional Items............................................................................................................................. 325
Putting It All Together........................................................................................................................... 326
Adding Server-Side Date Validation...............................................................................328
Defining the Regex Pattern to Validate Dates....................................................................................... 328
Adding a Validation Method to the Calendar Class............................................................................... 333
Returning an Error if the Dates Don’t Validate...................................................................................... 334
Adding Client-Side Date Validation................................................................................338
Creating a New JavaScript File to Validate the Date String.................................................................. 338
Including the New File in the Footer..................................................................................................... 339
Preventing the Form Submission if Validation Fails ............................................................................. 339
Summary .......................................................................................................................343
■
Do'stlaringiz bilan baham: