a!isPhoneNumber( phoneNumber, countryCode )
Returns true if the phoneNumber parameter contains a valid phone number, otherwise returns false. A phone number is considered valid if its area code and length are appropriate based upon the value of the countryCode parameter. This function supports countries and area codes for international numbers.
Keyword | Type | Description |
---|---|---|
|
Text |
A text value representing a phone number. Dashes, parentheses, periods, and blank spaces are allowed as separators. This parameter is required. |
|
Text Array |
One or more country codes used to validate the provided phone number. Country codes are represented as a two-letter ISO Alpha-2 code. For example, |
Boolean
The countryCode parameter can include one or more country codes. If you provide multiple country codes, the function will return true when it matches one of the provided country codes. See a list of country codes.
If the phone number does not match any of the provided country codes, the function will return false.
If no countryCode is provided, but the phone number contains an international code (+[country code]
), then the function will use the international code to determine if the provided phone number is valid.
For example, let's say you provide the phone number +34 913 30 28 00
without providing a countryCode parameter. Since +34
is the international code for Spain, the function will return true if the provided phone number is a Spain phone number.
Copy and paste these examples into an Appian Expression Editor to test out this function.
The countryCode parameter is optional if an international code (+<international code here>
) is provided as part of the phone number.
For example, the example below does not need the countryCode parameter since the international code (+52
) is part of the provided phone number.
1
2
3
a!isPhoneNumber(
phoneNumber: "+52 55 5487 3100",
)
Returns true
However, if you tried to use the following example, the function would return false
because there is no international code in the provided phone number, and no countryCode parameter.
1
2
3
a!isPhoneNumber(
phoneNumber: "55 5487 3100",
)
Returns false
1
2
3
4
5
6
a!isPhoneNumber(
/* This is a valid Cancun mobile phone number */
phoneNumber: "1-998-185-3133",
/* United States country code */
countryCode: "US",
)
Returns false
The countryCode parameter can accept an array of country codes. You may want to add a list of country codes if your application is used across multiple countries so you can validate different phone numbers accordingly.
In the example below, there are two country codes: Mexico and United States. Since this is phone number in Mexico, the function will ignore the first country code (United States) and validate as a phone number in Mexico.
1
2
3
4
5
6
a!isPhoneNumber(
/* This is a valid Cancun mobile phone number */
phoneNumber: "1-998-185-3133",
/* Mexico and United States country codes */
countryCode: {"US", "MX"}
)
Returns true
The following example uses the a!isPhoneNumber()
and a!formatPhoneNumber() functions to validate and format a user-provided phone number, which could be a phone number in the United States, Great Britain, or Germany.
Copy and paste this example into an Appian Interface to test out this function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
a!localVariables(
local!phoneNumber,
local!isNumberValid,
a!textField(
label: "Phone Number",
labelPosition: "ABOVE",
instructions: "Enter a phone number",
value: local!phoneNumber,
saveInto: {
local!phoneNumber,
a!save(
local!isNumberValid,
a!isPhoneNumber(
phoneNumber: local!phoneNumber,
countryCode: {"US", "GB", "DE"}
)
),
if(
local!isNumberValid,
a!save(
local!phoneNumber,
a!formatPhoneNumber(
phoneNumber: local!phoneNumber,
countryCode: {"US", "GB", "DE"},
outputFormat: "INTERNATIONAL",
)
),
{}
)
},
refreshAfter: "UNFOCUS",
validations: if(
local!isNumberValid,
"",
"Please enter a valid phone number."
),
inputPurpose: "PHONE_NUMBER",
)
)
Returns
Feature | Compatibility | Note |
---|---|---|
Portals | Compatible | |
Offline Mobile | Compatible | |
Sync-Time Custom Record Fields | Compatible | Can be used to create a custom record field that only evaluates at sync time. |
Real-Time Custom Record Fields | Incompatible | Custom record fields that evaluate in real time must be configured using one or more Custom Field functions. |
Process Reports | Incompatible | Cannot be used to configure a process report. |
Process Events | Incompatible | Cannot be used to configure a process event node, such as a start event or timer event. |