---
schema_version: "1"
id: 3b7b853a017f8dd5662bf17a05c08f0fcc85562dbbfb92e32a4bafed9c4c9417
title: Sample Contact Validation Rules
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/fields_useful_validation_formulas_contact.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.fields_useful_validation_formulas_contact.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 3a5c1964159e678b633156141316c05990ebe940731b119f1cc6760f12777f7c
description: Validation rules for various use cases, like requiring fields for mailing address, mailing street, and ZIP code.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Sample Contact Validation Rules

Validation rules for various use cases, like requiring fields for mailing address, mailing street, and ZIP code.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Contact Manager</strong>, <strong>Group</strong>, <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, <strong>Developer</strong>, and <strong>Database.com</strong> Editions</td></tr></tbody></table>

For more information on any of the formula functions used in these examples, see [Formula Operators and Functions](https://help.salesforce.com/s/articleView?id=platform.customize_functions.htm&release=264.0.0&type=5 "Use these operators and functions when building formulas. All functions are available everywhere that you can include a formula, such as formula fields, validation rules, approval processes, and workflow rules, unless otherwise specified.").

## Mailing Address Fields Are Required

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e102">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e105">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e102 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e105 ">Validates that the contact <samp class="parmname">Mailing Street</samp>,
              <samp class="parmname">Mailing City</samp>, and <samp class="parmname">Mailing Country</samp> are
              provided.
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e102 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e105 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>OR(
   ISBLANK( MailingStreet ),
   ISBLANK( MailingCity ),
   ISBLANK( MailingCountry )
)
</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e102 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e105 ">Mailing Street, City, and Country are required.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e102 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e105 ">
              <samp class="parmname">Top of Page</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Mailing Street Is Required

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e196">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e199">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e196 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e199 ">Validates that the contact <samp class="parmname">Mailing Street</samp> is
              provided.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e196 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e199 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>ISBLANK( MailingStreet )</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e196 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e199 ">Mailing Street is required.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e196 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e199 ">
              <samp class="parmname">Mailing Street</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Mailing Zip Code

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:23%">
          <col style="width:77%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e284">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e287">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e284 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e287 ">Validates that the contact <samp class="parmname">Mailing Zip/Postal Code</samp> is in
              99999 or 99999-9999 format if <samp class="parmname">Mailing Country</samp> is USA or
              blank.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e284 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e287 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>AND(
 OR(MailingCountry = "USA", ISBLANK(MailingCountry)),
  OR( 
   AND(LEN(MailingPostalCode) &lt;&gt;5, 
   LEN(MailingPostalCode) &lt;&gt; 10),
   NOT(CONTAINS("0123456789", 
      LEFT( MailingPostalCode, 1))),
   NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 2, 1))),
   NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 3, 1))),
   NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 4, 1))),
   NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 5, 1))),
   AND(
    LEN(MailingPostalCode) = 10,
   OR(
    MID( MailingPostalCode , 6, 1) &lt;&gt; "-",
    NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 7, 1))),
    NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 8, 1))),
    NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 9, 1))),
    NOT(CONTAINS("0123456789", 
      MID( MailingPostalCode , 10, 1)))
   )
  )
 )
)
</code></pre>
              <p>This example interprets a blank country as US. To use this example with
                other countries, remove the clause that checks the length of the country field.
                Also, validation rule criteria are case sensitive, so this rule is only enforced
                when the country is blank or “USA” in all capital letters. The rule
                is not enforced when the country is “usa.”</p>
              <p style="margin-bottom:0;">You can also
                validate zip codes using a regular expression; for an example of a formula using a
                regular expression, see <a href="https://help.salesforce.com/s/articleView?id=platform.customize_functions_regex.htm&amp;release=264.0.0&amp;type=5" title="Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, returns FALSE.">REGEX</a>.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e284 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e287 ">Zip code must be in 99999 or 99999-9999 format.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e284 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e287 ">
              <samp class="parmname">Mailing Zip/Postal Code</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Phone Number Has International Format

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e389">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e392">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e389 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e392 ">Validates that the <samp class="parmname">Phone</samp> number begins with a plus sign
              (+) for country code. Note that this validation rule conflicts with the ten-digit
              rule.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e389 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e392 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>LEFT(Phone, 1) &lt;&gt; "+"</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e389 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e392 ">Phone number must begin with + (country code).</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e389 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e392 ">
              <samp class="parmname">Phone</samp>
            </td>

          </tr>
        </tbody>
      </table>

## US Phone Number Has Ten Digits

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e477">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d151177e480">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e477 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e480 ">Validates that the <samp class="parmname">Phone</samp> number is in (999) 999-9999
              format. This works by using the REGEX function to check that the number has ten
              digits in the (999) 999-9999 format.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e477 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e480 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e477 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e480 ">US phone numbers should be in this format: (999) 999-9999.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e477 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d151177e480 ">
              <samp class="parmname">Phone</samp>
            </td>

          </tr>
        </tbody>
      </table>