public final class PhoneNumberUtil
extends java.lang.Object
PhoneNumber
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXCLUSION_PATTERN_PROPERTY
Name of the JCMS property used to exclude number from parsing (value is a regular expression).
|
static java.util.regex.Pattern |
exclusionPattern |
static java.lang.String |
REVISION |
Constructor and Description |
---|
PhoneNumberUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getPhoneHtml(java.lang.String number,
java.lang.String region)
Retrieve the specified telephone number properly formated in an HTML tag.
|
static PhoneNumber |
parseNumber(java.lang.String number,
java.lang.String region)
Parse a phone number string into a PhoneNumber instance.
|
public static final java.lang.String REVISION
public static final java.lang.String EXCLUSION_PATTERN_PROPERTY
If defined, all text that match the regular expression will be excluded from parsing into a valid PhoneNumber instance.
public static java.util.regex.Pattern exclusionPattern
public static java.lang.String getPhoneHtml(java.lang.String number, java.lang.String region)
Uses the RFC 3966 ("tel:" uri) as the anchor href, and the international format in the anchor body text, the original input is placed inside the title attribute.
Phone number is parsed with rule explained in parseNumber(String, String)
.
For example :
assertEquals("<a href=\"tel:+33-4-46-68-18-00\" title=\"+33 44 66 8 180 0\" class=\"tel\">+33 4 46 68 18 00</a>", PhoneTag.getPhoneHtml("+33 44 66 8 180 0", null)); final String sourceNumber = "0446681800"; assertEquals("<a href=\"tel:+41-44-668-18-00\" title=\"0446681800\" class=\"tel\">+41 44 668 18 00</a>", PhoneTag.getPhoneHtml(sourceNumber, "CH")); assertEquals("<a href=\"tel:+33-4-46-68-18-00\" title=\"0446681800\" class=\"tel\">+33 4 46 68 18 00</a>", PhoneTag.getPhoneHtml(sourceNumber, "FR"));If number could not be parsed, it is returned encoded for HTML, inside a dedicated span with the invalid-tel CSS class
assertEquals("<span class=\"invalid-tel\">do not call me!</span>", PhoneTag.getPhoneHtml("do not call me!", null));
number
- the telephone number to parse and displayregion
- the ISO 3166-1 two-letter region code that denotes the region that we are expecting
the number to be from. This is only used if the number being parsed is not written in international format.public static PhoneNumber parseNumber(java.lang.String number, java.lang.String region)
The following rules are applied regarding regionnal information :
number
- the telephone number to parseregion
- the ISO 3166-1 two-letter region code that denotes the region that we are expecting
the number to be from. This is only used if the number being parsed is not written in international format.Copyright © 2001-2017 Jalios SA. All Rights Reserved.