3
I have a field in a form that I need to validate with angular. The field should have up to 11 characters. If you have less than 5 should be displayed an error message requiring the user a correct numbering.
Angular Controller
angular.module('xxx') .controller('yyyController', function ($scope) {
var vm = $scope;
vm.validarCPF = function(){
if( condicao < 11){
//mensagem de erro
}
};
HTML code
<input type="text" name="cpf" id="cpf" ng-model="cpfusuario">
But what about the error message ? How to ask the user for a correct numbering ?
– alexjosesilva
And how to validate this in the controller ?? I don’t want to leave the html full of ng-s...
– alexjosesilva
I have to do the validation on the controller...
– alexjosesilva
The idea of using Angularjs is exactly to decrease javascript code. as for the message, this '<div role="Alert">' is responsible for displaying the message to the user. Remembering that this use of directives and HTML code instead of filling our javascript is one of the differentials of Angularjs and the use of HTML5.
– Julio Borges