02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

330<br />

CHAPTER 9 ■ PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS<br />

After saving the preceding code, reload http://localhost/regex.php in your browser to see all<br />

numeric characters highlighted (see Figure 9-15).<br />

Figure 9-15. Matching any numeric character<br />

Matching the Date Format<br />

To match the date format, start <strong>by</strong> matching exactly four digits at the beginning of the string to validate<br />

the year: /^(\d{4})/ (see Figure 9-16).<br />

Figure 9-16. Validating the year section of the date string<br />

Next, you need to validate the month <strong>by</strong> matching the hyphen <strong>and</strong> two more digits: /^(\d{4}(-<br />

\d{2}))/ (see Figure 9-17).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!