Class: CardSchemeValidator

sogv.CardSchemeValidator

This constraint ensures that a credit card number is valid for a given credit card company.

It can be used to validate the number before trying to initiate a payment through a payment gateway.

new sogv.CardSchemeValidator (data, options, optionRules, lang, internal)

Create a new Validator.

Name Type Description
data * The data which needs to be validated.
options Object The setting options
optionRules Object The validation rules for setting options.
lang String The language used by the application. Default: "en".
internal Boolean If this parameter is true, it means, that validation called from core.
Properties:
Name Type Description
alias Array

The aliases for the current validator.

They could be used in the short validation format.

Defined aliases: ['card-scheme', 'cs'].

options Object The description of the required options.
Example
var validator = new sogv.CardSchemeValidator(data, schemes);
if (false === validator.isValid()) {
     validator.errors().first();
}

Extends

Members

data * inherited

Data that needs to be validated.

lang String inherited

Language of error messages.

message String

The message shown when the value does not pass the CardScheme check.

Default: "Unsupported card type or invalid card number."

You can use the following parameters in this message:

Parameter Description
%%value%% The current (invalid) value

schemes String | Array

This option is required and represents the name of the number scheme used to validate the credit card number, it can either be a string or an array.

Valid values are:

  • AMEX
  • CHINA_UNIONPAY
  • DINERS
  • DISCOVER
  • INSTAPAYMENT
  • JCB
  • LASER
  • MAESTRO
  • MASTERCARD
  • MIR
  • UATP
  • VISA

For more information about the used schemes, see Wikipedia: Issuer identification number (IIN).

Methods

errors ()sogv.Error inherited

Return error errors

Returns:
Type Description
sogv.Error Error messages

isValid ()Boolean inherited overrides

Check if data valid.

Returns:
Type Description
Boolean Validation status