Validate_US
[ class tree: Validate_US ] [ index: Validate_US ] [ all elements ]

Class: Validate_US

Source Location: /Validate_US-0.5.5/Validate/US.php

Class Overview


Data validation class for the United States


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 Brent Cook

Methods


Inherited Variables

Inherited Methods


Class Details

[line 44]
Data validation class for the United States

This class provides methods to validate:

  • Social insurance number (aka SSN)
  • Region (state code)
  • Postal code
  • Telephone number



[ Top ]


Method Detail

phoneNumber   [line 559]

bool phoneNumber( string $number, [bool $requireAreaCode = true])

Validate a US phone number.

Allowed formats

  • xxxxxxx <-> 7 digits format
  • (xxx) xxx-xxxx <-> area code with brackets around it (or not) + phone number with dash or not
  • xxx xxx-xxxx <-> area code + number +- dash/space + 4 digits
  • (1|0) xxx xxx-xxxx <-> 1 or 0 + area code + 3 digits +- dash/space + 4 digits
  • xxxxxxxxxx <-> 10 digits

or various combination without spaces or dashes. THIS SHOULD EVENTUALLY take a FORMAT in the options, instead

  • Return: The valid or invalid phone number
  • Access: public

Parameters:

string   $number     phone to validate
bool   $requireAreaCode     require the area code? (default: true)

[ Top ]

postalCode   [line 225]

boolean postalCode( string $postalCode, [bool $strong = false])

Validates a US Postal Code format (ZIP code)
  • Return: TRUE if code is valid, FALSE otherwise
  • Todo: Integrate with USPS web API
  • Access: public

Parameters:

string   $postalCode     the ZIP code to validate
bool   $strong     optional; strong checks (e.g. against a list of postcodes) (not implanted)

[ Top ]

postalCodeByRegion   [line 245]

boolean postalCodeByRegion( string $postalCode, stirng $region)

Validates a US ZIP code by region (i.e. state)

Note: Some ZIP codes overlap between states. Do not use this data for reverse lookup of states.

  • Return: true if the ZIP code is valid for the specified region code, false otherwise.
  • Access: public

Parameters:

string   $postalCode     the ZIP code to validate.
stirng   $region     the 2-letter region code of the state.

[ Top ]

region   [line 477]

bool region( string $region)

Validates a "region" (i.e. state) code
  • Return: Whether the code is a valid state

Parameters:

string   $region     2-letter state code

[ Top ]

ssn   [line 54]

bool ssn( string $ssn, [array $high_groups = null])

Validates a social security number

Parameters:

string   $ssn     number to validate
array   $high_groups     array of highest issued SSN group numbers

[ Top ]

ssnCheck   [line 121]

bool ssnCheck( int $area, int $group, int $serial, array $high_groups)

checks if a Social Security Number is valid needs the first three digits and first two digits and the final four digits as separate integer parameters
  • Return: true if valid

Parameters:

int   $area     3-digit group in a SSN
int   $group     2-digit group in a SSN
int   $serial     4-digit group in a SSN
array   $high_groups     array of highest issued group numbers area number=>group number

[ Top ]

ssnGetHighGroups   [line 166]

array ssnGetHighGroups( [string $uri = 'http://www.ssa.gov/employer/highgroup.txt'], [bool $is_text = false])

Gets the most current list the highest SSN group numbers issued from the Social Security Administration website. This info can be cached for performance (and to lessen the load on the SSA website)

Parameters:

string   $uri     Path to the SSA highgroup.txt file
bool   $is_text     Take the $uri param as directly the contents

[ Top ]

ssnGroupRange   [line 86]

int ssnGroupRange( int $groupNumber)

Returns a range for a supplied group number, which is the middle, two-digit field of a SSN.

Group numbers are defined as follows:

  1. - Odd numbers, 01 to 09
  2. - Even numbers, 10 to 98
  3. - Even numbers, 02 to 08
  4. - Odd numbers, 11 to 99


Parameters:

int   $groupNumber     a group number to check, 00-99

[ Top ]


Documentation generated on Sat, 07 Apr 2012 22:00:07 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.