Methods
The Web library exposes its methods on the global DeviceAssure object once the script has loaded.
DeviceAssure.load()
The entrypoint for all integration scenarios. Collects the device data and, for Client to Server, sends it to the DeviceAssure service.
DeviceAssure.load({
licence: '<LICENCE_KEY>',
imei: '<IMEI>',
validateIMEIFormat: true,
storageType: 'none',
onSuccess: function(response) { console.log(response); },
onError: function(error) { console.log(error.message); }
});
See Client to Server, Server to Server and Configuration Options for full details on all available options.
DeviceAssure.validateIMEIFormat()
Checks that a value is a well formed IMEI, without loading the library or sending anything to the DeviceAssure service. Use it to validate a form field before a request is made.
| Parameter | Type | Default | Description |
|---|---|---|---|
imei | string | The value to check. | |
options.onError | function | Called with the reason the value was rejected. When omitted, the reason is thrown instead. |
Returns true when the value is a valid IMEI. When it is not, the reason is thrown, unless an onError callback is supplied, in which case that is called and false is returned.
Usage Examples
// A valid IMEI returns true
DeviceAssure.validateIMEIFormat('490154203237518');
// Without a callback, the reason is thrown
try {
DeviceAssure.validateIMEIFormat('490154203237519');
}
catch (e) {
console.log(e.message); // 'Invalid IMEI format'
}
// With a callback, the reason is delivered to it and false is returned
DeviceAssure.validateIMEIFormat('490154203237519', {
onError: function(error) { console.log(error.message); }
});
Requirements
- No licence is required. The check runs entirely in the browser.
- Only a 15 digit IMEI is accepted. It is the only form carrying a check digit, so it is the only one the checksum can verify. A 16 digit IMEISV gives that position over to the software version number.
- The value is validated exactly as it is given, so any whitespace is a failure. Trim the value first if your form allows it.
Error Messages
| Message | Cause |
|---|---|
IMEI is not a string. | The value is not a string. |
IMEI is not present, please provide one. | The value is empty or is all whitespace. |
IMEI must contain digits only. | The value holds letters, whitespace or special characters. |
IMEI must be 15 digits. | The value is not 15 digits long. |
Invalid IMEI format | The check digit does not add up. |
Note: To have the library run this check for you as part of a validation request, use the
validateIMEIFormatoption instead. See IMEI Format Validation.
See Also
- Configuration Options - Storage, caching, tags, and IMEI options
- Client to Server - Direct validation from the browser
- Server to Server - Validation via your backend server
- QR Code Methods - The
DeviceAssure.qr()andDeviceAssure.parseQrRedirect()methods