nigerian-mobile-validator
Version:
The most rigorous, up-to-date library for validating Nigerian mobile numbers. Fully NCC-compliant, and security-focused, with enterprise-grade features to prevent the business risks of validation failures in regulated industries.
74 lines (73 loc) • 3.72 kB
JavaScript
// src/number-validation/mobile-validation-status.ts
/**
* An enum that describes the error/success messages after validation.
*/
export var MobileValidationStatus;
(function (MobileValidationStatus) {
MobileValidationStatus[MobileValidationStatus["IncorrectNumberOfDigits"] = 0] = "IncorrectNumberOfDigits";
MobileValidationStatus[MobileValidationStatus["NotNigerianNumber"] = 1] = "NotNigerianNumber";
MobileValidationStatus[MobileValidationStatus["ContainsNonNumericChars"] = 3] = "ContainsNonNumericChars";
MobileValidationStatus[MobileValidationStatus["IncorrectNetworkCode"] = 4] = "IncorrectNetworkCode";
MobileValidationStatus[MobileValidationStatus["InvalidSubscriberNumber"] = 5] = "InvalidSubscriberNumber";
MobileValidationStatus[MobileValidationStatus["UnassignedNetworkCode"] = 6] = "UnassignedNetworkCode";
MobileValidationStatus[MobileValidationStatus["SharedVASNetworkCode"] = 7] = "SharedVASNetworkCode";
MobileValidationStatus[MobileValidationStatus["WithdrawnNetworkCode"] = 8] = "WithdrawnNetworkCode";
MobileValidationStatus[MobileValidationStatus["ReservedNetworkCode"] = 9] = "ReservedNetworkCode";
MobileValidationStatus[MobileValidationStatus["RateLimitExceeded"] = 10] = "RateLimitExceeded";
MobileValidationStatus[MobileValidationStatus["ReturnedNetworkCode"] = 11] = "ReturnedNetworkCode";
MobileValidationStatus[MobileValidationStatus["Success"] = 99] = "Success";
})(MobileValidationStatus || (MobileValidationStatus = {}));
/**
* Object containing user-friendly and developer-friendly messages
* for each validation status.
*/
export const ValidationStatusMessages = {
[]: {
userMessage: 'Start with 0, 234, or +234',
devMessage: 'Not a Nigerian number format'
},
[]: {
userMessage: 'Number is too long or too short',
devMessage: 'Incorrect number of digits'
},
[]: {
userMessage: 'Only enter numbers 0-9',
devMessage: 'Must only contain digits'
},
[]: {
userMessage: 'Not a Nigerian number',
devMessage: 'Mobile network code not found'
},
[]: {
userMessage: 'Number is not correct',
devMessage: 'Subscriber number is not valid for this network code'
},
[]: {
userMessage: 'No mobile network uses this code',
devMessage: 'Network code not assigned to any telco'
},
[]: {
userMessage: 'No mobile network uses this code',
devMessage: 'Network code is Shared VAS (not assigned to any telco)'
},
[]: {
userMessage: 'This code has been withdrawn',
devMessage: 'Network code has been withdrawn by NCC'
},
[]: {
userMessage: 'This code is reserved',
devMessage: 'Network code is reserved for special services'
},
[]: {
userMessage: 'Too many validation attempts',
devMessage: 'Validation rate limit exceeded'
},
[]: {
userMessage: 'This code is marked as \'returned\'',
devMessage: 'Network code has been returned'
},
[]: {
userMessage: 'Nice! This is a Nigerian mobile number',
devMessage: 'Success, this is a valid Nigerian mobile number'
}
};