Salesforce の REGEX 関数を用いて、電話番号や郵便番号などの入力規則を設定する方法を解説します。具体的な正規表現の例を紹介し、各国のフォーマットに対応した入力検証を行います。
注意 : 以下の表の”_”は、任意のスペースを表しています (REGEX 関数ではスペースの有無は区別しません)。
| 説明 | 形式 | 検証 |
| アメリカの電話番号 (内線番号なし) | (999)_999-9999 +1_(999)_999-9999 | !REGEX(Phone,"^((\\+1)?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4})?$") |
| アメリカの電話番号 (内線番号あり) | 上記の形式に加え、以下の形式です。 (999)_999-9999_x999… (999)_999-9999_Ext._999… (999)_999-9999_ext:_999… (内線番号の長さに制限はありません) ext や x の後に : や . が付いていてもかまいません。また、番号の前に +1 が付いていてもかまいません。 | !REGEX(Phone,"^((\\+1)?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4})(\\s?(x|([Ee]xt[\\.:]?\\s?))\\d+)?)?$") |
| 社会保障番号 | 999-99-9999 | !REGEX(Social_Security_Number__c,"^(\\d{3}\\-\\d{2}-\\d{4})?$" |
| アメリカの郵便番号 (5 桁) | 12345 | !REGEX(PostalCode,"^\\d{5}?$") |
| アメリカの郵便番号 (5 桁もしくは 9 桁) | 12345 12345-6789 | !REGEX(PostalCode,"^(\\d{5}(\\-\\d{4})?)?$") |
| ブラジルの電話 (内線番号なし) | (99)_9999-9999 (99)_99999-9999 +55 (99)_9999-9999 +55 (99)_99999-9999 | !REGEX(Phone,"^((\\+\\d{2}\\s)?\\(\\d{2}\\)\\s?\\d{4}\\d?\\-\\d{4})?$") |
| ブラジルの電話番号 (内線番号あり) | 上記の式に加え、以下の形式です。 [上記のような電話番号] ramal: 999… [上記のような電話番号] ramal 999… | !REGEX(Phone,"^((\\+\\d{2}\\s)?\\(\\d{2}\\)\\s?\\d{4}\\d?\\-\\d{4}(\\sramal:?\\s\\d+)?)?$") |
| ブラジルの法人納税管理番号 | 99.999.999/9999-99 | !REGEX(CNPJ__c,"^(\\d{2}\\.\\d{3}\\.\\d{3}/\\d{4}\\-\\d{2})?$") |
| ブラジルの郵便番号(5 桁もしくは 8 桁) | 99999-999 99999 | !REGEX(PostalCode,"^(\\d{5}(\\-\\d{3})?)?$") |
| ブラジルの納税者番号 | 999.999.999-99 | !REGEX(CPF__c,"^(\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2})?$") |
| 日本の電話番号 (内線番号なし) | 99-9999-9999 999-999-9999 9999-99-9999 9999-999-999 | !REGEX(Phone,"^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$") |
| 日本の郵便番号 (ハイフン「-」必要) | 999-9999 | !REGEX(PostalCode,"^[0-9]{3}-[0-9]{4}$") |
| 日本の郵便番号 (ハイフン「-」あり、なし両対応) | 999-9999 9999999 | !REGEX(PostalCode,"^([0-9]{3}-[0-9]{4})?$|^[0-9]{7}+$") |
| 先頭文字を大文字で記載する単語や名前 regex 関数に記載されているすべてのアクセント付き文字が対象であり、先頭文字を大文字 (先頭文字は大文字で、残りは小文字) で記載します。ただし、(一部の言語の) 特殊な文字、da、de、di、do および d' の接頭辞は除きます。 | Smith John de Souza Rio de Janeiro Brasília d'Onofrio di Lorenço | !REGEX(FirstName, "^((^|\\s)(((([DdO]')|Mc|Mac)?[A-ZÃÁÂÀÄÇÉÈÊËÍÌÎÏÕÒÔÓÖÛÚÙÜ][a-zãáàâäçéèêëíìîïñõôóòöûúùü]*)|(da|de|di|do)))*$") |
| 複数行が入力できるテキスト項目にて、ユーザが改行を入力するのを防ぎます。¹ | REGEX( ShippingStreet , '(.*\r?\n.*)*') | |
| 複数行が入力できるテキスト項目にて、最大 3 行までの入力を許可します。¹ | REGEX( ShippingStreet , '(.*\r?\n.*){3,}') | |
000386675

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.