2016-04-26 20 views
-2

私はangularjsにhtmlを使ってコードを書いています。このMINLENGTHとMAXLENGTH検証に.here私のコード HTMLコードを作業されていません。なぜminlengthとmaxlength検証が機能していないのですか?

<input type="text" id="healthcomplaint" ng-model="userDetails.healthcomplaint" style="color:#4a5665;" class="form-control" name="healthcomplaint" ng-required="true" ng-minlength="3" ng-maxlength="120" ng-pattern="/^[a-zA-Z0-9\s\[\]\.,\_\/\-#']*$/" tabindex="8"> 
<span class="ng-hide error_txt" ng-show="submitted && info.healthcomplaint.$error.required">Please enter health complaint.</span>  
<span class="ng-hide error_txt" ng-show="info.healthcomplaint.$error.minlength">health complaint should have at least 3 characters.</span> 
<span class="ng-hide error_txt" ng-show="info.healthcomplaint.$error.maxlength">health complaint should not exceed 120 characters.</span> 
+0

submitted &&を交換しますが、周囲のフォームのHTMLを含めることはできますか?あなたがここにあるものに根本的に間違っているものは何もありません( 'ng-required =" true "'は重複しますが動作します) – jdphenix

+0

thnk u、しかし動作しません。plsは代用を教えてください – shiv

+0

** HTMLフォーム?**およびブラウザコンソールからのエラー(ある場合) – jdphenix

答えて

0

Working Demo

<form name='myForm' novalidate> 

    <input type="text" id="healthcomplaint" ng-model="userDetails.healthcomplaint" style="color:#4a5665;" class="form-control" name="healthcomplaint" ng-required="true" ng-minlength="3" ng-maxlength="120" ng-pattern="/^[a-zA-Z0-9\s\[\]\.,\_\/\-#']*$/" tabindex="8"> 
    <span class="ng-hide error_txt" ng-show="myForm.healthcomplaint.$dirty && myForm.healthcomplaint.$error.required">Please enter health complaint.</span>  
    <span class="ng-hide error_txt" ng-show="myForm.healthcomplaint.$error.minlength">health complaint should have at least 3 characters.</span> 
    <span class="ng-hide error_txt" ng-show="myForm.healthcomplaint.$error.maxlength">health complaint should not exceed 120 characters.</span> 

    <input type='submit'> 
    </form> 

のこのパターンを使用して更新

私はspanを次からsubmitted &&を削除しました。あなたがsubmittedを使用したい場合は、myForm.submitted &&

<span class="ng-hide error_txt" ng-show="submitted && info.healthcomplaint.$error.required">Please enter health complaint.</span> 
+0

私のコードも同じです....... – shiv

+0

@shiv updated my answer。 –

+0

minlengthとmaxlengthが機能していない – shiv

0

は、ブラウザのネイティブの検証を無効にする<form>novalidateを使用してください。 、代わりにng-patternpattern="[0-9]{9}"

関連する問題