Skip to content

Validation

Validation methods operate on an NF.Phone (from NF.parse) or, for string overloads, on raw text without parsing first.

NF.isValid

Returns whether a parsed number is valid for its region and number type.

Signatures

global static Boolean isValid(NF.Phone phone)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number. Must not be null.

Returns

true if the number is a valid phone number; false otherwise.

Throws

None.

libphonenumber

PhoneNumberUtil.isValidNumber(PhoneNumber)

Example

NF.Phone phone = NF.parse(contact.Phone, 'US');
if (NF.isValid(phone)) {
contact.Phone = NF.format(phone, NF.Format.E164);
}

NF.isValidForRegion

Returns whether the number is valid and belongs to the given region.

Signatures

global static Boolean isValidForRegion(NF.Phone phone, String regionCode)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.
regionCodeStringISO region to test (e.g. US).

Returns

true if valid for that region.

Throws

None.

libphonenumber

PhoneNumberUtil.isValidNumberForRegion(PhoneNumber, String)

Example

NF.Phone phone = NF.parse('650-253-0000', 'US');
Boolean usNumber = NF.isValidForRegion(phone, 'US'); // true

NF.isPossible

Checks whether a number has a possible length and structure (weaker than valid).

Signatures

global static Boolean isPossible(NF.Phone phone)

Use when you already parsed the value. No parsing overhead.

global static Boolean isPossible(String rawNumber, String defaultRegion)

Use on Lead import or web-form fields without calling NF.parse first. Parses internally, then checks possibility.

Parameters

Parameters depend on the signature; see Signatures above.

NameTypeDescription
phoneNF.PhoneParsed number (isPossible(NF.Phone)).
rawNumberStringRaw text (isPossible(String, String)).
defaultRegionStringRegion when no + is present (string overload).

Returns

true if the number is possible; does not guarantee validity.

Throws

The isPossible(String, String) signature may throw NF.ParseException if parsing fails internally.

libphonenumber

PhoneNumberUtil.isPossibleNumber(PhoneNumber) / isPossibleNumber(CharSequence, String)

Example

// String overload: quick check on a dirty import row
Boolean possible = NF.isPossible('+1 650-253-0000', 'US'); // true
// Phone overload: after parse
NF.Phone phone = NF.parse(contact.Phone, 'US');
Boolean possibleParsed = NF.isPossible(phone); // true

NF.isPossibleForType

Checks whether the number is possible for a specific line type.

Signatures

global static Boolean isPossibleForType(NF.Phone phone, NF.NumberType typeValue)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.
typeValueNF.NumberTypeType to test (e.g. MOBILE). See Types.

Returns

true if possible for that type.

Throws

None.

libphonenumber

PhoneNumberUtil.isPossibleNumberForType(PhoneNumber, PhoneNumberType)

Example

NF.Phone phone = NF.parse('+1 650-253-0000', 'US');
Boolean ok = NF.isPossibleForType(phone, NF.NumberType.FIXED_LINE_OR_MOBILE);

NF.possibleReason

Returns why a number is only possible, or confirms it is possible.

Signatures

global static NF.ValidationResult possibleReason(NF.Phone phone)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.

Returns

NF.ValidationResult; typically IS_POSSIBLE or a failure reason. See Types.

Throws

None.

libphonenumber

PhoneNumberUtil.isPossibleNumberWithReason(PhoneNumber)

Example

NF.ValidationResult reason = NF.possibleReason(phone);
// reason → NF.ValidationResult.IS_POSSIBLE

NF.possibleReasonForType

Like NF.possibleReason, scoped to a number type.

Signatures

global static NF.ValidationResult possibleReasonForType(NF.Phone phone, NF.NumberType typeValue)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.
typeValueNF.NumberTypeType to evaluate.

Returns

Throws

None.

libphonenumber

PhoneNumberUtil.isPossibleNumberForTypeWithReason(PhoneNumber, PhoneNumberType)

Example

NF.ValidationResult r = NF.possibleReasonForType(phone, NF.NumberType.MOBILE);

NF.typeOf

Classifies a valid number (mobile, fixed line, toll-free, etc.).

Signatures

global static NF.NumberType typeOf(NF.Phone phone)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.

Returns

NF.NumberType; e.g. MOBILE, FIXED_LINE_OR_MOBILE, UNKNOWN.

Throws

None.

libphonenumber

PhoneNumberUtil.getNumberType(PhoneNumber)

Example

NF.NumberType lineType = NF.typeOf(phone);
// lineType → NF.NumberType.FIXED_LINE_OR_MOBILE (US example)

NF.isGeographical

Returns whether a number or type is geographical (area-code based).

Signatures

global static Boolean isGeographical(NF.Phone phone)

Classifies a parsed number.

global static Boolean isGeographical(NF.NumberType typeValue, Integer countryCallingCode)

Classifies a type and calling code without a parsed number (e.g. routing rules).

Parameters

Parameters depend on the signature; see Signatures above.

NameTypeDescription
phoneNF.PhoneParsed number (isGeographical(NF.Phone)).
typeValueNF.NumberTypeNumber type (isGeographical(NF.NumberType, Integer)).
countryCallingCodeIntegerCountry calling code (type + code overload).

Returns

true if geographical.

Throws

None.

libphonenumber

PhoneNumberUtil.isNumberGeographical(PhoneNumber) / isNumberGeographical(PhoneNumberType, int)

Example

Boolean geo = NF.isGeographical(phone);
Boolean mobileGeo = NF.isGeographical(NF.NumberType.MOBILE, 1); // false for US mobile

NF.isAlphaNumber

Returns whether the string contains alphabetic characters as used in vanity numbers.

Signatures

global static Boolean isAlphaNumber(String value)

Parameters

NameTypeDescription
valueStringRaw phone text.

Returns

true if the string is considered an alpha number.

Throws

None.

libphonenumber

PhoneNumberUtil.isAlphaNumber(CharSequence)

Example

Boolean vanity = NF.isAlphaNumber('1800 MICROSOFT'); // true

NF.isNumberMatch

Compares two numbers for equality at various strictness levels.

Signatures

global static NF.MatchType isNumberMatch(NF.Phone first, NF.Phone second)

Compare two parsed values (e.g. duplicate detection after normalization).

global static NF.MatchType isNumberMatch(String first, String second)

Compare two raw strings with default parsing. Useful in batch dedup without building NF.Phone objects.

global static NF.MatchType isNumberMatch(NF.Phone first, String second)

Compare stored parsed value against user input or import text.

Parameters

Parameters depend on the signature; see Signatures above.

NameTypeDescription
firstNF.Phone or StringFirst number.
secondNF.Phone or StringSecond number.

Returns

NF.MatchType (e.g. EXACT_MATCH, NSN_MATCH, NO_MATCH). See Types.

Throws

Signatures that take String arguments may throw NF.ParseException.

libphonenumber

PhoneNumberUtil.isNumberMatch(…) (overloads)

Example

// Phone + String: stored E.164 vs user-typed display
NF.Phone stored = NF.parse('+16502530000', 'US');
NF.MatchType match = NF.isNumberMatch(stored, '+1 650-253-0000');
// match → EXACT_MATCH
// String + String: import dedup without explicit parse
NF.MatchType raw = NF.isNumberMatch('650-253-0000', '(650) 253-0000');
// raw → EXACT_MATCH (with default region applied during parse)
// Phone + Phone
NF.MatchType both = NF.isNumberMatch(stored, stored.copy());
// both → EXACT_MATCH

NF.truncateTooLongNumber

Truncates a number that is too long to fit metadata rules, mutating the passed NF.Phone.

Signatures

global static Boolean truncateTooLongNumber(NF.Phone phone)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number to truncate in place.

Returns

true if truncation was applied.

Throws

None.

libphonenumber

PhoneNumberUtil.truncateTooLongNumber(PhoneNumber)

Example

NF.Phone phone = NF.parse(longInput, 'US');
if (NF.truncateTooLongNumber(phone)) {
// phone national number was shortened
}

NF.canBeInternationallyDialled

Returns whether the number can be dialled from outside its home country.

Signatures

global static Boolean canBeInternationallyDialled(NF.Phone phone)

Parameters

NameTypeDescription
phoneNF.PhoneParsed number.

Returns

true if international dialling is allowed for this number.

Throws

None.

libphonenumber

PhoneNumberUtil.canBeInternationallyDialled(PhoneNumber)

Example

NF.Phone phone = NF.parse('+1 650-253-0000', 'US');
Boolean intl = NF.canBeInternationallyDialled(phone); // true