tailieunhanh - JavaScript Bible, Gold Edition part 118

JavaScript Bible, Gold Edition part 118. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 1018 Part IV JavaScript Core Language Reference they return different values a Boolean value for test and a character offset value for search or -1 if no match is found . Which method you choose depends on whether you need only a true false verdict on a match or the location within the main string of the start of the substring. Listing 38-1 demonstrates the search method on a page that lets you get the Boolean and offset values for a match. Some default text and regular expression is provided it looks for a five-digit number . You can experiment with other strings and regular expressions. Because this script creates a regular expression object with the new RegExp constructor method you do not include the literal forward slashes around the regular expression. Listing 38-1 Looking for a Match HTML HEAD TITLE Got a Match TITLE SCRIPT LANGUAGE function findIt form var re new RegExp var input if re -1 0 .checked true else 1 .checked true function locatelt form var re new RegExp var input re SCRIPT HEAD BODY B Use a regular expression to test for the existence of a string B HR F0RM Enter some text to be searched BR TEXTAREA NAME main C0LS 40 ROWS 4 WRAP virtual The most famous ZIP code on Earth may be 90210. TEXTAREA BR Enter a regular expression to search BR INPUT TYPE text NAME regexp SIZE 30 VALUE b d d d d d b P INPUT TYPE button VALUE Is There a Match onClick findIt INPUT TYPE radio NAME output Yes INPUT TYPE radio NAME output No P INPUT TYPE button VALUE Where is it onClick locateIt INPUT TYPE text NAME offset SIZE 4 P INPUT TYPE reset F0RM BODY HTML Chapter 38 The Regular Expression and RegExp Objects 1019 Getting information about a match For the next application example the task is not only to verify that a one-field date entry is in the desired format but also to extract match components of the

TỪ KHÓA LIÊN QUAN