【Android】EditTextでの入力制限(バリデーション)の種別まとめ
入力欄を表示するEditTextで、入力するデータの種別に応じて指定値をandroid:inputType="指定値"
に指定することで、入力の制限(バリデーション)ができるようになります。
種類がたくさんあるので以下にまとめます。
指定値の種別
指定値 | 動作 |
---|---|
none | 入力不可 |
text | 文字を入力する場合 |
textCapCharacters | すべて大文字で入力する場合 |
textCapWords | 単語の先頭を大文字で入力する場合 |
textCapSentences | 文章の先頭を大文字で入力する場合 |
textAutoCorrect | 文字のスペルミスを自動で修正する場合 |
textAutoComplete | 文字の補完入力する場合 |
textMultiLine | 文字を複数行入力する場合 |
textImeMultiLine | 通常の文字入力時は複数行入力を許可せず、IMEによって複数行入力を設定する場合 |
textUri | URLを入力する場合 |
textEmailAddress | メールアドレスを入力する場合 |
textEmailSubject | メールの件名を入力する場合 |
textShortMessage | ショートメッセージを入力する場合 |
textLongMessage | ロングメッセージを入力する場合 |
textPersonName | 人名を入力する場合 |
textPostalAddress | 住所を入力する場合 |
textPassword | パスワード入力する場合 |
textVisiblePassword | 隠蔽せずにパスワード入力する場合 |
textWebEditText | HTMLを入力する場合 |
textFilter | 他のデータでフィルタされた文字を入力する場合 |
textPhonetic | 発音表記を入力する場合 |
number | 数値入力する場合 |
numberSigned | 符号付きの数値を入力する場合 |
numberDecimal | 小数入力する場合 |
phone | 電話番号を入力する場合 |
datetime | 日付時刻を入力する場合 |
date | 日付を入力する場合 |
time | 時刻を入力する場合 |
参考サイト: