AngularJSng-minlengthディレクティブ


入力値が5文字より短い場合は、エラーを表示します。

<form name="myForm">

<input name="myInput" ng-model="myInput" ng-minlength="5">

<h1 ng-if="!myForm.myInput.$valid">The value is too short</h1>

</form>

定義と使用法

ディレクティブはng-minlength、入力フィールドとフォームのバリデーターに制限を追加します。

値のng-minlength長さが指定された長さよりも短い場合、ディレクティブは入力フィールドの「無効な」状態を追加します。

注:値が空の場合、有効と見なされます。


構文

<input type="text" ng-minlength="number"></input>

主にテキストタイプの<input>要素でサポートされていますが、ユーザー入力を可能にする他の要素でも使用できます。


パラメータ値

Value Description
number A number representing the minimum number of characters legal for the input field.