
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
angular-form-validate
Advanced tools
[](https://github.com/jpkleemans/angular-validate/releases/latest) [](https://github.com/jpkle
Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
Download Angular Validate:
$ bower install jpkleemans-angular-validate
$ git clone https://github.com/jpkleemans/angular-validate.git
When using one of the last two methods make sure you also download the latest release of the jQuery Validation Plugin.
Include both jquery.validate.min.js
and angular-validate.min.js
in your HTML page:
<!-- jQuery scripts -->
<script src="path/to/jquery.min.js"></script>
<script src="path/to/jquery.validate.min.js"></script>
<!-- Angular scripts -->
<script src="path/to/angular.min.js"></script>
<script src="path/to/angular-validate.min.js"></script>
Inject the ngValidate
module as a dependency into your Angular application:
angular.module('myApp', ['ngValidate']);
Add the ng-validate directive to your form and pass the validation options as value:
<form name="registerform" ng-submit="register(registerform)" ng-validate="validationOptions">
<input type="email" name="email">
<input type="password" name="password">
</form>
Then set the validation options in your controller:
$scope.validationOptions = {
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
}
},
messages: {
email: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of name@domain.com"
},
password: {
required: "You must enter a password",
minlength: "Your password must have a minimum length of 6 characters"
}
}
}
Or (for simple forms) insert the options directly without using a controller:
<form name="simpleform" ng-submit="register(simpleform)" ng-validate="{rules: {name: "required"}}">
For all available options, see: http://jqueryvalidation.org/validate#validate-options
Now you can validate the form by calling validate()
on the form instance:
$scope.register = function (form) {
if(form.validate()) {
// Form is valid!
}
}
You can also pass your validation options as the first parameter of
validate()
.
$window.alert("There are " + form.numberOfInvalids() + " invalid fields.");
A set of standard validation rules is provided by the jQuery Validation Plugin:
More info: http://jqueryvalidation.org/documentation/#link-list-of-built-in-validation-methods
Angular Validate ships with a $validatorProvider, that you can use to configure default validation options and custom validation rules.
angular.module('myApp')
.config(function ($validatorProvider) {
$validatorProvider.setDefaults({
errorElement: 'span',
errorClass: 'help-block'
});
});
More info: http://jqueryvalidation.org/jQuery.validator.setDefaults
angular.module('myApp')
.config(function ($validatorProvider) {
$validatorProvider.addMethod("domain", function (value, element) {
return this.optional(element) || /^http:\/\/mydomain.com/.test(value);
}, "Please specify the correct domain for your documents");
});
More info: http://jqueryvalidation.org/jQuery.validator.addMethod
FAQs
[](https://github.com/jpkleemans/angular-validate/releases/latest) [](https://github.com/jpkle
We found that angular-form-validate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.