Could you please guide me on how to implement validation in an input field using AngularJS? I am working on a form that is dynamically generated through JSON. I have already added validation for required fields - if the user submits a blank value, it shows a red border. However, I need additional validations such as:
- Users should not enter digits or (123) in their names
- Users should not enter invalid values like "test" or "abc". If these values are entered, the form should be marked as invalid.
Is it possible to add custom validations to 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;
};