createNewFormat()
createNewFormat() creates a new token format which can be used with the insert() method.
Note
This method is overloaded to allow the use of regular expressions, and again to allow the optional tokenLength parameter.
The first method listed below simplifies the process of creating new formats by using Java regular expression syntax. As indicated, this method requires only the format name and two pieces of data. For more information, see Create Custom Token Formats with Java Regular Expressions.
Syntax
public int createNewFormat (string description, string splitter, string splicer)
public int createNewFormat (int leadPositions, int trailPositions, string leadMask, int luhnCheck)
public int createNewFormat (int leadPositions, int trailPositions, string leadMask, int luhnCheck, int tokenLength)
Request Parameters
Parameters | Data Types | Descriptions |
---|---|---|
description | string | Descriptive name for the token format. |
splitter | string | Splits the input into groups. |
splicer | string | Combines groups into resulting token. |
leadPositions | integer | Number of positions to preserve (if any) on the left side of the value. |
trailPositions | integer | Number of positions to preserve (if any) on the right side of the value. |
leadMask | string | A fixed number of digits to mask the leading positions. For example, if leadMask is set to 7777, the first four digits of the token will be 7’s. When leadMask is set, the leadPositions value is ignored. For example, for input value 1234 5678 9012 3456, setting leadMask to 7777 and leadPosition to 6 results in 7777 8031 4902 1531 and not 7777 5631 4902 1531. leadPositions + trailPositions or leadMask + trailPositions cannot be larger than the token length. Either the value is set in the tokenLength parameter or in the Token Vault’s token column. If this rule is ignored, an exception is thrown. |
luhnCheck | integer | Indicates if the token should fail the check (-1), pass the check (1), or does not matter (0). |
tokenLength | integer | This parameter is optional. It indicates the length of the token if it is different from the input data. tokenLength cannot be larger than the Token Vault’s token column. |
Returned Values
An integer representing the new token format, the value will be greater than 100.
Exception
Passes an exception if the below parameters are invalid or the tokenLength is negative or longer than 256 characters.
leadPositions
trailPositions
leadMask
luhnCheck
Example
int tokenFormat = createNewFormat(7, 0, null, 1);
A token is created which retains the first 7 characters of the input value and passes the luhn check. You can then use this new token format in the insert() method, like this:
String token = TokenService.insert(creditCard, CCVault, tokenFormat, true);