Mobile

object Mobile(source)

Validator, formatter, and masker for Indian mobile numbers (TRAI numbering plan).

Accepts 10-digit numbers starting with 6, 7, 8, or 9. Common input forms are normalised before validation: raw digits, E.164 (+91 prefix), leading zero (common Indian dialing convention), spaces, and hyphens are all accepted.

This object is stateless and thread-safe.

Example

Mobile.validate("9876543210")               // ValidationResult.Valid
Mobile.validate("+91 98765 43210") // ValidationResult.Valid
Mobile.validate("1234567890") // ValidationResult.Invalid(INVALID_PREFIX)
Mobile.format("9876543210", true) // "+91 98765 43210"
Mobile.mask("9876543210") // "XXXXXX3210"

Samples

Mobile.validate("9876543210") // ValidationResult.Valid
Mobile.format("9876543210", withCountryCode = true) // "+91 98765 43210"
Mobile.mask("9876543210") // "XXXXXX3210"

Functions

Link copied to clipboard
fun format(value: String, withCountryCode: Boolean = false): String

Formats a validated mobile number for human-readable display.

Link copied to clipboard
fun isValid(value: String): Boolean

Returns true if validate returns ValidationResult.Valid.

Link copied to clipboard
fun mask(value: String, visibleStart: Int = 0, visibleEnd: Int = 4, maskChar: Char = 'X'): String

Masks a mobile number for PII-safe display.

Link copied to clipboard

Validates an Indian mobile number.