電話番号とEメールアドレスの記入ミスを除外したい

こんにちは。UiPath Studio Community Edition 2023.6.1版ユーザの初心者です。
Edgeに自動ログイン後、Excelの顧客データを1件ずつWebに転記するワークフローをデバッグ中です。
電話番号とEメールアドレスの記入ミスをはじいて、アプリケーション例外をthrowしたいのですが、条件文はどうなりますでしょうか?
Matchesアクティビティ利用でもOKです。

■電話番号の記入ミスで例外をthrowしない条件

・半角数値であること。但し半角"-"は混在許可
・最初の数値は0であること

■Eメールアドレスで例外をthrowしない条件

・半角文字であること。但し半角カナは除外
・必ず"@"をひとつだけ含むこと。

@gorby
Assign activity:

  • Variable: phoneNumber (String)
  • Value: “123-4567” (Replace with the phone number variable you are using)

If activity:

  • Condition: System.Text.RegularExpressions.Regex.IsMatch(phoneNumber, "^0[\d-]+$")
    (This condition checks if the phone number starts with 0 and consists of half-width numeric characters and optional hyphens)

    Then block (No exception is thrown if the condition is true):

    • Do the necessary workflow steps for transferring the phone number.

    Else block (Exception is thrown if the condition is false):

    • Throw an application exception with an appropriate error message.

@gorby
Assign activity:

  • Variable: emailAddress (String)
  • Value: “example@example.com” (Replace with the email address variable you are using)

If activity:

  • Condition: System.Text.RegularExpressions.Regex.IsMatch(emailAddress, "^[ -~]+@[^ -~]+$")
    (This condition checks if the email address consists of half-width characters, excluding half-width katakana, and contains exactly one “@” symbol)

    Then block (No exception is thrown if the condition is true):

    • Do the necessary workflow steps for transferring the email address.

    Else block (Exception is thrown if the condition is false):

    • Throw an application exception with an appropriate error message.

@gorby

Can you provide some different samples of valud phone numbers and email id’s so that an appropriate regex can be provided

For email if you want to check for only single @ the. Can use System.Text.RegularExpressions.Regex.Matches(str,"@").Count=1

For validating a complete email then can try this as well as generic one

Sytem.Text.RegularExpressions.Regex.IsMatch(str,"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\n")

Cheers

Hi @gorby

Assign phoneNumber = “0123-456-7890” // The phone number you want to validate

Matches activity:
   Input: phoneNumber
   Pattern: "^0[\d\-]+$"
If activity:
   Condition: phoneNumberMatches.Count > 0
      Then : Enter the phone number in the web browser.
      Else : Throw activity with Application Exception message: "Invalid phone number"

Continue with the rest of your workflow if the phone number is valid.

Assign emailAddress = “test@example.com” // The email address you want to validate

Matches activity:
   Input: emailAddress
   Pattern: "^[a-zA-Z0-9._]+(\-*)[A-Z|a-z|0-9]*\@+[A-Za-z0-9._]*"
If activity:
   Condition: emailMatches.Count > 0
    Then : Enter the Mail id in the web browser
    Else : Throw activity with Application Exception message: "Invalid email address"

Continue with the rest of your workflow if the email address is valid.

Hope it helps!!

こんにちは

まず電話番号ですが、以下が良いと思います。上記で\dを使っている例がりますが、\dは全角数字もマッチしますので、今回のケースでは不適と思います。

System.Text.RegularExpressions.Regex.IsMatch(strPhone,"^0[-0-9]*[0-9]$")

image

メールアドレスは正規表現ビルダーで出てくるものをベースにした以下でよいのではと思います。

System.Text.RegularExpressions.Regex.IsMatch(strMail,"^((?>[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+\x20*|""((?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*""\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+)+|""((?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*"")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$")

image