Language

SaveInfo.Builder.SetValidator(IValidator) メソッド

定義

ユーザー入力の検証に使用するオブジェクトを設定します。入力が無効な場合、オートフィル保存 UI は表示されません。

[Android.Runtime.Register("setValidator", "(Landroid/service/autofill/Validator;)Landroid/service/autofill/SaveInfo$Builder;", "", ApiSince=27)]
public Android.Service.Autofill.SaveInfo.Builder SetValidator(Android.Service.Autofill.IValidator validator);
[<Android.Runtime.Register("setValidator", "(Landroid/service/autofill/Validator;)Landroid/service/autofill/SaveInfo$Builder;", "", ApiSince=27)>]
member this.SetValidator : Android.Service.Autofill.IValidator -> Android.Service.Autofill.SaveInfo.Builder

パラメーター

validator
IValidator

Android システムによって提供される実装。 この値は null にすることはできません。

戻り値

このビルダー。 この値は null にすることはできません。

属性

注釈

ユーザー入力の検証に使用するオブジェクトを設定します。入力が無効な場合、オートフィル保存 UI は表示されません。

通常、クレジット カード番号を検証するために使用されます。 例 :

正確に 16 桁のクレジット番号の検証コントロール:

Validator validator = new RegexValidator(ccNumberId, Pattern.compile("^\\d{16}$"));

Luhn チェックサムを渡す必要があり、16 桁または 108 から始まる 15 桁のクレジット番号を検証します。

import static android.service.autofill.Validators.and;
import static android.service.autofill.Validators.or;

Validator validator =
  and(
    new LuhnChecksumValidator(ccNumberId),
    or(
      new RegexValidator(ccNumberId, Pattern.compile("^\\d{16}$")),
      new RegexValidator(ccNumberId, Pattern.compile("^108\\d{12}$"))
    )
  );

注: 上記の例は説明を目的としています。OR 部分に対して 1 つの正規表現を使用して、同じ検証コントロールを作成できます。

Validator validator =
  and(
    new LuhnChecksumValidator(ccNumberId),
    new RegexValidator(ccNumberId, Pattern.compile("^(\\d{16}|108\\d{12})$"))
  );

4 つのフィールドに含まれるクレジット番号のバリデーター。各フィールドに正確に 4 桁の数字が必要です。

import static android.service.autofill.Validators.and;

Validator validator =
  and(
    new RegexValidator(ccNumberId1, Pattern.compile("^\\d{4}$")),
    new RegexValidator(ccNumberId2, Pattern.compile("^\\d{4}$")),
    new RegexValidator(ccNumberId3, Pattern.compile("^\\d{4}$")),
    new RegexValidator(ccNumberId4, Pattern.compile("^\\d{4}$"))
  );

android.service.autofill.SaveInfo.Builder.setValidatorの Android リファレンス。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象