Runtime verified Test scripts included

Syntax

IsPhoneNumber(value)  →  boolean
1 argument — exactly

Parameters

Name Type Required Description
value string | number Yes Phone number to validate; strip any leading plus sign or country code first

Example

%%[ VAR @ok SET @ok = IsPhoneNumber("425-555-0142") ]%%
%%=v(@ok)=%%

Renders True.

A number captured in international form has to lose its prefix before it will pass, since the plus sign alone is enough to fail the check:

%%[
  VAR @input, @ok
  SET @input = Replace(RequestParameter("phone"), "+1", "")
  SET @ok = IsPhoneNumber(@input)
]%%
%%=IIf(@ok, "we can text you", "we need a North American number")=%%

Return value

booleanTrue for a number inside the numbering plan, False otherwise.

Both literals were produced in the same render, as the capitalised words True and False. They are genuine booleans: each compares equal to the corresponding boolean value.

Behaviour

The scope is the North American Numbering Plan, not the United States. A Dominican Republic number and a Canadian number both return True; a valid United Kingdom number returns False. Reading the function as US-only is too narrow, and reading it as a general phone check is too wide.

Separators are tolerated, other characters are not. Dashes, dots, spaces and parentheses all pass. A vanity number spelling letters — 425-555-CALL — returns False, so non-numeric characters are not simply ignored.

A leading plus sign fails on its own. IsPhoneNumber("+14255550142") returns False while the same subscriber digits without the prefix return True.

Digit count is not what decides the answer. IsPhoneNumber("1234567890") has ten digits and returns False; a seven-digit number returns False too.

An unquoted number works. IsPhoneNumber(6585550142) returns the same True as its quoted form, and the empty string returns False.

Which inputs are accepted

Call Renders
IsPhoneNumber("4255550142") True
IsPhoneNumber("425-555-0142") True
IsPhoneNumber("425.555.0185") True
IsPhoneNumber("(829) 555-0142") True
IsPhoneNumber("647 555 0123") True
IsPhoneNumber(6585550142) True
IsPhoneNumber("+14255550142") False
IsPhoneNumber("425-555-CALL") False
IsPhoneNumber("0161 496 0009") False
IsPhoneNumber("1234567890") False
IsPhoneNumber("5550142") False
IsPhoneNumber("") False
Show test script
%%[
  VAR @b
  SET @b = RequestParameter("b")

  /* known-good control: renders on every request, so a run of HTTP 422s
     can be told apart from a broken deploy */
  OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))

  /* the accepted/rejected matrix - safe on every request */
  OutputLine(Concat("--- P start ---"))
  OutputLine(Concat("P1_plain10=[", IsPhoneNumber("4255550142"), "]"))
  OutputLine(Concat("P2_dashes=[", IsPhoneNumber("425-555-0142"), "]"))
  OutputLine(Concat("P3_parens=[", IsPhoneNumber("(829) 555-0142"), "]"))
  OutputLine(Concat("P4_plus_cc=[", IsPhoneNumber("+14255550142"), "]"))
  OutputLine(Concat("P5_short=[", IsPhoneNumber("5550142"), "]"))
  OutputLine(Concat("P6_letters=[", IsPhoneNumber("425-555-CALL"), "]"))
  OutputLine(Concat("P7_dots=[", IsPhoneNumber("425.555.0185"), "]"))
  OutputLine(Concat("P8_uk=[", IsPhoneNumber("0161 496 0009"), "]"))
  OutputLine(Concat("P9_1234567890=[", IsPhoneNumber("1234567890"), "]"))
  OutputLine(Concat("P10_spaces=[", IsPhoneNumber("647 555 0123"), "]"))
  OutputLine(Concat("--- P done ---"))

  /* the empty string, in its own branch: the sibling IsCHTMLBrowser aborts
     on it, so the four functions must not share one empty-string branch */
  IF @b == "p_empty" THEN
    OutputLine(Concat("--- p_empty start ---"))
    OutputLine(Concat("P_EMPTY=[", IsPhoneNumber(""), "]"))
    OutputLine(Concat("--- p_empty done ---"))
  ENDIF

  /* an unquoted number rather than a numeric string */
  IF @b == "g_num" THEN
    OutputLine(Concat("--- g_num start ---"))
    OutputLine(Concat("P_NUM=[", IsPhoneNumber(6585550142), "]"))
    OutputLine(Concat("--- g_num done ---"))
  ENDIF

  /* the rendered literals compared against real booleans */
  IF @b == "g_tok" THEN
    OutputLine(Concat("--- g_tok start ---"))
    OutputLine(Concat("P_EQTRUE=[", IIf(IsPhoneNumber("4255550142") == true, "matches-true", "no"), "]"))
    OutputLine(Concat("P_EQFALSE=[", IIf(IsPhoneNumber("0161 496 0009") == false, "matches-false", "no"), "]"))
    OutputLine(Concat("--- g_tok done ---"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next No

See also