String API

The kony.string namespace provides static string functions that augment the functions in the String type that is available by default. For more information see, https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/string.

NOTE: JavaScript distinguishes between String objects and primitive string values.

String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the new keyword) are primitive strings. JavaScript automatically converts primitive strings and String objects, making it possible to use String object methods for primitive strings. In cases where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript automatically wraps the string primitive and calls the method or performs the property lookup.

The String API contains the kony.string Namespace and related API elements:

Function Description
kony.string.containsChars Verifies if any one of the specified set of characters is available in the given string and returns a boolean value.
kony.string.containsOnlyGivenChars Verifies if only (and only) the specified set of characters is available in the given string and returns a boolean value.
kony.string.containsNoGivenChars Verifies that the input string does not contain any of the specified characters and returns a boolean value.
kony.string.endsWith Returns a boolean value indicating if the source string ends with the specified string.
kony.string.equalsIgnoreCase Determines whether two strings contain the same data, ignoring the case of the letters in the String.
kony.string.isAsciiAlpha Verifies if the input string contains only ASCII alphabet characters and returns a boolean value.
kony.string.isAsciiAlphaNumeric Verifies if the input string contains only ASCII alphabet characters and numbers, and returns a boolean value.
kony.string.isNumeric Verifies if the input string contains only numeric characters, and returns a boolean value.
kony.string.isValidEmail Verifies if the input string is a valid email address and returns a boolean value.
kony.string.rep Generates a string which is equivalent to n copies of the source string concatenated together.
kony.string.reverse Reverses the characters in the source string.
kony.string.startsWith Returns a boolean value indicating if the source string begins with the specified string.
kony.string.trim Removes the leading and ending spaces from the source string.
 

Use the kony.string.containsChars function to check whether the specified set of characters are available in the given string. To verify that only a specified set of characters is available in the given string, use the kony.string.containsOnlyGivenChars function. If you want to verify that no given characters are available in the given string, use the kony.string.containsNoGivenChars function. You can check whether a string starts or ends with a specified string using the kony.string.startsWith or the kony.string.endsWith functions respectively. Use the kony.string.equalsIgnoreCase function to determine whether two strings contain the same data, ignoring the case of the letters in the String. To check whether the input string contains only ASCII alphabet characters, use the kony.string.isAsciiAlpha function that returns a boolean value. Use the kony.string.isAsciiAlphaNumeric function to verify if the input string contains only ASCII alphabet characters and numbers. The kony.string.isNumeric function verifies if the input string contains only numeric characters. Use the kony.string.isValidEmail function to verify if the specified string is a valid email address. The kony.string.reverse reverses the characters in the source string. Use the kony.string.trim to remove the leading and ending spaces from a source string.

All the functions in the Kony String API are in the kony.string namespace. The kony.string namespace contains functions that are deprecated and must therefore not be used in new software development. However, documentation for them is provided to help with the maintenance of legacy apps.

To view the functionality of the String API in action, download the sample application from the link below. Once the application is downloaded, build and preview the application using the Quantum App.