How to show form errors on submit in Angularjs

13 |

Following is the sample code for showing all form errors. It will be very useful for the developers when they are unable to track the errors. <table> <tr ng-repeat=”(key, errors) in form.$error track by $index”> <td><strong>{{ key }}</strong> errors <ul> <li ng-repeat=”err in errors”>{{ err.$name }} has an error: <strong>{{ key }}</strong>.</li> </ul> </td> </tr> </table>

Angularjs form validation with ngPattern

0 |

ngPattern is one of the useful things for validation in AnjularJs. AnjularJs ngPattern adds pattern to ngmodel. It is mainly used in text-based form controls. The following are some of the sample patterns: Email <input type=”text” ng-model=”mail” name=”mail” ng-pattern=”/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i” >   Phone <input type=”text” ng-model=”mobile” name=”mobile” ng-pattern=”/^(\+\91{1,2}[- ])\d{10}$/” />   Landline Phone <input type=”text” ng-model=”landLine” […]