Mobile
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"Content copied to clipboard
Samples
Mobile.validate("9876543210") // ValidationResult.Valid
Mobile.format("9876543210", withCountryCode = true) // "+91 98765 43210"
Mobile.mask("9876543210") // "XXXXXX3210"Content copied to clipboard