kafe.string.validate

Class

Version 1.0.0

String validation tools.

Source: dist/string-validate.js

Methods

isCreditCard

Checks if a string is a valid credit card number and fits a specific brand pattern.

Source: http://www.regular-expressions.info/creditcard.html

isCreditCard
  • string
  • creditcard
Boolean

Parameters:

  • string String
  • creditcard String

    A credit card brand abbreviation. Possible values are visa, mastercard, americanexpress, dinersclub, discover, jcb.

Returns:

Boolean

If true, the string is a valid credit card number.

Example:

kafe.string.validate.isCreditCard('k789 kafe 3789', 'mc');
					// returns false
kafe.string.validate.isCreditCard('1234 5678 1234 5678', 'vi');
					// returns true

isEmail

Checks if a string is a valid email address.

isEmail
  • string
Boolean

Parameters:

  • string String

Returns:

Boolean

If true, the string is a valid email address.

Example:

kafe.string.validate.isEmail('mailbox@mailaddress');
					// returns false
kafe.string.validate.isEmail('kafe.feedback@absolunet.com');
					// returns true

isLuhnAlgorithm

Checks if a string passes the Luhn algorithm.

Source: https://gist.github.com/2134376 Source: http://jsperf.com/credit-card-validator/7

isLuhnAlgorithm
  • string
Boolean

Parameters:

  • string String

Returns:

Boolean

If true, the string passes the Luhn algorithm.

Example:

kafe.string.validate.isLuhn('79927398713');
					// returns true

isNum

Checks if a string is numeric.

isNum
  • string
Boolean

Parameters:

  • string String

Returns:

Boolean

If true, the string could be converted to a number.

Example:

kafe.string.validate.isNum('k4f3');
					// returns false
kafe.string.validate.isNum('43');
					// returns true

isPostalCode

Checks if a string is a valid or part of a valid Canadian postal code.

isPostalCode
  • string
  • format] Validation pattern (Regular expression). Default pattern is *([a-z][0-9
Boolean

Parameters:

  • string String
  • [format] Validation pattern (Regular expression). Default pattern is *([a-z][0-9] String Optional

    ){3}*. Can also be set to A1A 1A1 for a single precise value or as A1A and 1A1 when divided into two values.

Returns:

Boolean

If true, the string matches the validation format.

Example:

kafe.string.validate.isPostalCode('KAF123');
					// returns false
kafe.string.validate.isPostalCode('K4F 3F3', 'A1A 1A1');
					// returns true