could you please tell me how to add validation. in input field in angular js ? Actually I am making a form which is generated by json .I already add validation of required .if user submitted blank value it show "red border" .But I need more validation like
- User will not enter "digits" or (123) in user name and last name
- User will not enter invalid value example "test" ,"abc".These two are invalid values.if user enter these value form should be invalid .
can I add custom validation in fields
http://plnkr.co/edit/YmIMEGHm7E48wZQT9ZSb?p=preview
$scope.isSubmitClicked = false;
$scope.myform =''
$scope.c ={
"ABC": {
"type": "LABEL",
"editable": false
},
"Title": {
"value": "Ms",
"type": "FIELD",
"editable": false,
"dataType": "",
"required":false
},
"First Name": {
"value": "",
"type": "FIELD",
"editable": true,
"dataType": "",
"required":true
},
"Middle Name": {
"value": "",
"type": "FIELD",
"editable": true,
"dataType": "",
"required":false
},
"Last Name": {
"value": "",
"type": "FIELD",
"editable": true,
"dataType": "",
"required":true
}
}
$scope.submit = function ($event) {
$scope.isSubmitClicked = true;
};
require: 'ngModel', and link it with controller:link: function (s, e, a, ctrl) {, then your custom validation will go intoctrl.$validators.myValidation = function(modelValue, viewValue){...}. Its job is to returntrueorfalseif something is valid or not. The error will show up inmyform[inputName].$error.myValidation