format

fun format(value: String, withCountryCode: Boolean = false): String(source)

Formats a validated mobile number for human-readable display.

Input is normalised the same way as validate before formatting. Output formats:

  • withCountryCode = false (default): "98765 43210" (space after 5th digit)

  • withCountryCode = true: "+91 98765 43210"

Return

Formatted display string.

Parameters

value

Raw mobile number string in any common Indian format.

withCountryCode

If true, prepends +91 to the formatted output. Default: false.

Throws

if value is not a valid Indian mobile number. The exception message includes the (truncated) input for diagnostics.

Samples

check(Mobile.format("9876543210") == "98765 43210")
check(Mobile.format("9876543210", withCountryCode = true) == "+91 98765 43210")