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

Class: Validate_CA

Source Location: /Validate_CA-0.2.0/Validate/CA.php

Class Overview

Data validation class for Canada



  • Release: @package_version@


  • 1997-2005 Philippe Jausions


Inherited Variables

Inherited Methods

Class Details

[line 42]
Data validation class for Canada

This class provides methods to validate:

  • Social Insurance Number (aka SIN)
  • Province code
  • Telephone number
  • Postal code

[ Top ]

Method Detail

phoneNumber   [line 228]

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

Validates a Canadian phone number.

Canada and the United States share the same numbering plan, hence you can also call Validate_US::phoneNumber()

Can allow only seven digit numbers. Also allows the formats, (xxx) xxx-xxxx, xxx xxx-xxxx, And now x (xxx) xxx-xxxx or various combination without spaces, dashes. THIS SHOULD EVENTUALLY take a FORMAT in the options, instead

  • Return: Whether the phone number is valid.
  • Access: public


string   $number     phone to validate
bool   $withAreaCode     require the area code?

[ Top ]

postalCode   [line 117]

boolean postalCode( string $postalCode, [string $province = ''])

Validates a Canadian Postal Code
  • Return: TRUE if code is valid, FALSE otherwise
  • Link: c154
  • Access: public


string   $postalCode     the postal code to validate
string   $province     the province code

[ Top ]

region   [line 186]

bool region( string $region)

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


string   $region     2-letter province code

[ Top ]

ssn   [line 90]

bool ssn( string $ssn, [int $expiryDate = null])

Validates a Canadian social insurance number (SIN)

For unification between country-based validation packages, this method is named ssn()


string   $ssn     number to validate
int   $expiryDate     expiry date for SIN starting with a 9 (UNIX timestamp)

[ Top ]

_luhn   [line 60]

bool _luhn( string $number)

Validates a number according to Luhn check algorithm

This function checks given number according Luhn check algorithm. It is published on several places, see links:


string   $number     number to check

[ Top ]

Documentation generated on Tue, 15 Dec 2009 23:00:02 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.