Legacy Knowledge Base
公開されました Jul. 2, 2025

Liferayフォームフィールドを検証するために期待される正規表現構文

Written By

Kanchan Bisht

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

問題

  • 正しい電子メール ID が入力されていても、フィールドを検証するために 'Regex Expressions' を操作しているときに、フォーム UI に無効なエラー メッセージが表示されます。
    • 以下の正規表現を使用して電子メール フィールドを検証する際に発生する問題
      • /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
      • ^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-] +)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
      • ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/ =?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$

Environment

  • Liferay 7.2

解決策

  • フォームは、 Java 構文に基づく特定の形式の正規表現を理解します。
  • このコンテキストでは、正規表現の開始バーと終了バーを削除する必要があります
    • エラー構文 : /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    • 作業構文: ^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,3})+$
  • \w などの文字クラスのメタ文字の前に余分なバックスラッシュを避ける
    • エラー構文:
      • ^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=? `{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
      • ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'* +/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$
    • 作業構文:
      • ^[\w!#$%&'*+/=?`{|}~^-]+(?:\.[\w!#$%&'*+/=?`{|}~^-]+ )*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$
      • ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\.[a-zA-Z0-9_!#$%&'*+/= ?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$

追加情報

  • 電子メール タイプの入力フィールドに指定された正規表現。

Validation-With-RegularExpression.png

Did this article resolve your issue ?

Legacy Knowledge Base