Prev | Current Page 339 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

S. Postal
Service (http://www.usps.com/ncsc/lookups/usps_abbreviations.html). For
example, OH, CA, and NY are all valid, whereas CC, DUI, and BASF are not.
ssn(): Validates an SSN by not only checking the SSN syntax but also reviewing
validation information made available via the Social Security Administration
Web site (http://www.ssa.gov/), returning TRUE on success, and FALSE otherwise.
It accepts SSNs in a variety of formats, including xxx-xx-xxxx, xxx xx xxx,
xxx/xx/xxxx, xxx\txx\txxxx (\t = tab), xxx\nxx\nxxxx (\n = newline), or any
nine-digit combination thereof involving dashes, spaces, forward slashes, tabs, or
newline characters. For example, 479-35-6432 and 591467543 are valid, whereas
999999999, 777665555, and 45678 are not.
Once you have an understanding of the method definitions, implementation is
trivial. For example, suppose you want to validate a phone number. Just include the
Validate_US class and call phoneNumber() like so:
276 CHAPTER 9 ?–  STRINGS AND REGULAR EXPRESSIONS
include "Validate/US.php";
$validate = new Validate_US();
echo $validate->phoneNumber("614-999-9999") ? "Valid!" : "Not valid!";
?>
Because phoneNumber() returns a Boolean, in this example the Valid! message will
be returned. Contrast this with supplying 614-876530932 to phoneNumber(), which will
inform the user of an invalid phone number.
Summary
Many of the functions introduced in this chapter will be among the most commonly
used within your PHP applications, as they form the crux of the language??™s stringmanipulation
capabilities.


Pages:
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351