angularjs의 폼 검증 1

<form name="myForm" novalidate>
		<div>
		<input   ng-pattern="/^\d{3}$/" name="name" required  ng-minlength="3" maxlength="3" ng-model="user.name" />
		<span class="error" ng-show="myForm.name.$dirty&&myForm.name.$invalid"> 3 </span>
		<span class="error" ng-show="jscontrol&&myForm.name.$pristine&&myForm.name.$error.required"> 3 </span>
		</div>
		<div>
		<input   ng-pattern="/^.{1,15}$/" name="addr" required  ng-minlength="1" maxlength="15" ng-model="user.addr" />
		<span class="error" ng-show="myForm.addr.$dirty&&myForm.addr.$invalid"> 15 </span>
		<span class="error" ng-show="jscontrol&&myForm.addr.$pristine&&myForm.addr.$error.required"> 15 </span>
		</div>
		<button ng-click="save();"> </button>

	</form>

 
app.controller('formCtrl', ['$scope', function($scope){
	$scope.save = function(){
		$scope.jscontrol=true;
		if($scope.myForm.$valid){
			alert(" ");
		}else{
			alert(" ");
		}
	}
}])

간결한 원생의 표 검증

좋은 웹페이지 즐겨찾기