TCNPJValidator
extends TFieldValidator
in package
CNPJ validation (Valid only in Brazil)
Tags
Table of Contents
Constants
- WEIGHTS : mixed = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
- Validation weights
Methods
- validate() : mixed
- Validate a given value
- calculateDigit() : int
- Calculate a verification digit
- charValue() : int
- Convert a character to its numeric value according to the official CNPJ alphanumeric rule
- checkDigits() : bool
- Verify check digits
- isValidFormat() : bool
- Verify basic format rules
Constants
WEIGHTS
Validation weights
private
mixed
WEIGHTS
= [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
Methods
validate()
Validate a given value
public
validate(mixed $label, mixed $value[, mixed $parameters = null ]) : mixed
Parameters
- $label : mixed
-
Identifies the value to be validated in case of exception
- $value : mixed
-
Value to be validated
- $parameters : mixed = null
-
Additional parameters for validation
calculateDigit()
Calculate a verification digit
private
calculateDigit(string $value, int $offset) : int
Parameters
- $value : string
- $offset : int
Return values
intcharValue()
Convert a character to its numeric value according to the official CNPJ alphanumeric rule
private
charValue(string $char) : int
Parameters
- $char : string
Return values
intcheckDigits()
Verify check digits
private
checkDigits(string $cnpj) : bool
Parameters
- $cnpj : string
Return values
boolisValidFormat()
Verify basic format rules
private
isValidFormat(string $cnpj) : bool
Parameters
- $cnpj : string