Tương tác giữa PHP và jQuery - part 32

CHAPTER 9 ■■■ Performing Form Validation with Regular Expressions It’s your responsibility as a developer to ensure that your users’ data is useful to your app, so you need to ensure that critical information is validated before storing it in your database. In the case of the calendar application, the date format is critical: if the format isn’t correct, the app will fail in several places. To verify that only valid dates are allowed into the database, you’ll use regular expressions (regexes), which are powerful pattern-matching tools that allow developers much more control over data than a strict string comparison search. Before. | C H A P T E R 9 Performing Form Validation with Regular Expressions It s your responsibility as a developer to ensure that your users data is useful to your app so you need to ensure that critical information is validated before storing it in your database. In the case of the calendar application the date format is critical if the format isn t correct the app will fail in several places. To verify that only valid dates are allowed into the database you ll use regular expressions regexes which are powerful pattern-matching tools that allow developers much more control over data than a strict string comparison search. Before you can get started with adding validation to your application you need to get comfortable using regular expressions. In the first section of this chapter you ll learn how to use the basic syntax of regexes. Then you ll put regexes to work doing server-side and client-side validation. Getting Comfortable with Regular Expressions Regular expressions are often perceived as intimidating difficult tools. In fact regexes have such a bad reputation among programmers that discussions about them are often peppered with this quote Some people when confronted with a problem think I know I ll use regular expressions. Now they have two problems. Jamie Zawinski This sentiment is not entirely unfounded because regular expressions come with a complex syntax and little margin for error. However after overcoming the initial learning curve regexes are an incredibly powerful tool with myriad applications in day-to-day programming. Understanding Basic Regular Expression Syntax In this book you ll learn Perl-Compatible Regular Expression PCRE syntax. This syntax is compatible with PHP and JavaScript as well as most other programming languages. 311 CHAPTER 9 PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS Note You can read more about PCRE at http wiki Perl_Compatible_Regular_Expressions. Setting up a Test File To learn how to use regexes you ll .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
187    27    1    02-12-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.