LoginSignup
1
1

REGEXを使ったVR

Last updated at Posted at 2022-05-01

Answersで回答する時に使う情報のまとめに戻る


改行

REGEX(<field name>, '(.*\r?\n.*)*')

全角文字

これは全角だけOKの場合の例

AND(
NOT(ISBLANK(  Street__c ) ),
NOT(REGEX(Street__c, "[^ -~。-゚]*") )
)

半角カナと数字を制御する入力規則について

NOT(REGEX( 項目 , "^[ヲ. ー-゚()]*$"))
NOT(REGEX( admissible__c  , "^[0-9T]*$" ))
AND(
NOT(ISBLANK( Name)),
NOT(REGEX( Name,"^[ヲ-ン]+[ ]{0,1}+[ ]{0,1}+[ヲ-ン]*$"))
)

メールアドレス

email@email..com (with an additional dot).

REGEX({!Email_Address}, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z]{2,4}$")

なかなか素晴らしい。

3行までは認めているが、さらに1行は50文字までとしたい。

AND( 
NOT(ISBLANK(BillingStreet)), 
(NOT(OR( REGEX(BillingStreet,".{0,50}"), REGEX(BillingStreet,".{0,50}\r\n.{0,50}\r\n.{0,50}"))))
)

Validation rule for Billing Address

AND( 
NOT(ISBLANK( Name)), 
NOT(REGEX(Name, "^[-@\"#!$\\%^&*()_+|~=`{}\\[\\]:;'<>?,.\\/a-zA-Z0-9 \\x5C]*$")) 
)

Regex formula for validation rule

カンマで繰り返し何個も入力できる場合の書き方

(){0,)が重要

AND(
NOT(ISBLANK( Additional_order_numbers__c )),
NOT(REGEX( Additional_order_numbers__c ,'(^[0-9]{8}[ ][0-9]{2}[ ][0-9]{5}|^[0-9]{3}[ ][0-9]{9}|^[0-9]{10})(,[0-9]{8}[ ][0-9]{2}[ ][0-9]{5}|,[0-9]{3}[ ][0-9]{9}|,[0-9]{10}){0,}$'))
)

validation rule - REGEX

説明を求める質問(英語の回答例として使える)

Can somebody please explain me what this REGEX validation means?

NOT(REGEX(Phone, "[+]{0,1}[-\\s\\.\\/0-9()]+"))

組み合わせ例

Complex validation rule formula

AND(
OR(
ISNEW(),
DATEVALUE(CreatedDate) = DATEVALUE("2021-11-17")
),
OR(
AND(
NOT(ISBLANK(field__c)),
LEFT(field__c,1) <>"0",
OR(
NOT(REGEX(field__c,"^[0-9a-zA-Z]*$")),
NOT(OR(
LEN(field__c) = 9,
LEN(field__c) = 10,
LEN(field__c) = 15
))
)
),
AND(
NOT(ISBLANK(field__c)),
LEFT(field__c,1) ="0",
NOT(REGEX(field__c,"^[0-9]{3}-[0-9]{3}-[0-9]{3}$"))
)
)
)

|,^,` を入力させない

AND( 
NOT(ISBLANK( field__c)), 
NOT(REGEX(field__c, "^[-@\"#!$\\%&*()_+~={}\\[\\]:;'<>?,.\\/a-zA-Z0-9 \\x5C]*$")) 
)

この数字を 15 文字で表示したいのですが、最初の文字は 1 または 2 にし、文字を含めないでください。

REGEX(TEXT( Numero_de_securite_social__c) , "^([12]{2})([0-9]{0,13})$")

Error: Incorrect argument type for function 'REGEX()'.

数値型だとエラーになるのでTEXT関数を使う。

REGEX(text, regex_text) and replace text with the text field, and regex_text with the regular expression you want to match.

image.png

正規表現の詳しい説明

ここれから抜粋
Explorations Into Salesforce

使用できる場所

  • バリデーションルール(フィールドで必要なものと一致するREGEXを作成する場合、次のように最終結果を否定する必要があることを意味します。)
  • Apex
  • フロー

使用できない場所

  • VF Page
  • 数式項目

説明

  • ()でグループ化
  • .(ピリオド)–行末記号以外の任意の文字に一致します
  • ?(疑問符)–前のトークンを0回または1回一致させます
  • *(アスタリスク)–前のトークンと0回以上一致する
  • +(プラス記号)–前のトークンと1回以上一致する
    +{n} –前のトークンをn回一致させる
    +{n,} –前のトークンとn回以上 一致する
    注:{0,}は*と同等であり、{1,}は+と同等です。
  • {n,m} –前のトークンと少なくともn回、m回 以下一致する
    注:{0,1}は?と同等です
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1