Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
angular-validation
Advanced tools
AngularJS > 1.2.0, 1.3.0-beta
http://huei90.github.io/angular-validation/
http://plnkr.co/edit/Nwk9cT (Bootstrap framework)
MIT
angular.module('yourApp', ['validation']);
Add Valid Message (error, success) for validation required
required-error-message
and required-success-message
<label>Required</label>
<input type="text"
name="require"
ng-model="form.required"
validator="required"
required-error-message="Required"
required-success-message="Good Required"/>
<!-- or you can try
required-error-message="{{ RequiredMsg }}"
-->
Add Valid Message (error, success) for validation email
email-error-message
and email-success-message
<label>Email</label>
<input type="text"
name="email"
ng-model="form.email"
validator="email"
email-error-message="Error Email"
email-success-message="Good Email"/>
Use Default Valid Message
you don't need to give valid message
<label>Number</label>
<input type="text" name="number" ng-model="form.number" validator="number"/>
Don't show the Valid Message no-validation-message="true"
<label>Number</label>
<input type="text" name="number" ng-model="form.number" validator="number" no-validation-message="true"/>
<!-- or {{ your.Scope.Name }} -->
<input type="text" name="number" ng-model="form.number" validator="number" no-validation-message="{{ noValidationMessage }}"/>
Add Valid Callback Function, invalid-callback
& valid-callback
<label>Required (Invalid Callback alert)</label>
<input type="text" name="requiredCallback" ng-model="form.requiredCallback" validator="required" invalid-callback='error("Must be Required");'/>
Select the validation method watch
blur
submit
, default as watch
validationProvider.validate(form).success(callback).error(callback)
use callback to continue your submit
<label>Watch method</label>
<input type="text" name="number" ng-model="form.number" validator="number" valid-method="watch"/>
<input type="text" name="number" ng-model="form.number" validator="number"/>
<label>Blur method</label>
<input type="text" name="number" ng-model="form.number" validator="number" valid-method="blur"/>
<label>Submit method</label>
<form name="Form">
<input type="text" name="number" ng-model="form.number" validator="number" valid-method="submit"/>
<button ng-click="form.submit(Form)"></button>
</form>
<script>
// ... validate method, it will check `checkValid(Form)`
$scope.form = {
submit: function (form) {
$validationProvider.validate(form)
.success(successCallback)
.error(errorCallback);
}
};
// ...
</script>
Setup a new Validation setExpression()
setDefaultMsg()
with RegExp
or Function
<!-- View -->
<label>IP address (Custom setup the new validator - RegExp)</label>
<input type="text" name="ip" ng-model="form.ip" validator="ip"/>
<label>Huei (Custom setup the new validator - Function)</label>
<input type="text" name="huei" ng-model="form.huei" validator="huei"/>
// Controller
// your module
angular.module('yourApp', ['validation']);
// Now you can use validationProvider in your Angular Controller
function validation($scope, $injector) {
var validationProvider = $injector.get('validationProvider'); // inject validationProvider
// Setup `ip` validation
var expression = {
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
};
var validMsg = {
ip: {
error: 'This isn\'t ip address',
success: 'It\'s ip'
}
};
validationProvider.setExpression(expression); // set expression
validationProvider.setDefaultMsg(validMsg); // set valid message
// Setup `huei` validation
validationProvider.setExpression({
/**
* @param value , user input
* @returns {boolean} true iff valid
*/
huei: function (value) {
return value === 'Huei Tan';
// or you can do
return $q.all([obj]).then(function () {
// ...
return true;
})
}
});
validationProvider.setDefaultMsg({
huei: {
error: 'This should be Huei Tan',
success: 'Thanks!'
}
});
}
Check form whether valid, return true
if valid. checkValid()
Reset the specific Form. reset()
<form name="Form">
...
<!-- Check the entire form valid from angular-validation `valid` -->
<button ng-disabled="form.checkValid()"></button>
<!-- or Check the specific form(Form) valid from angular `$valid` -->
<button ng-disabled="form.checkValid(Form)"></button>
<!-- Reset the specific Form -->
<button ng-click="form.reset(Form)"></button>
</form>
// ... checkValid
$scope.form.checkValid = validationProvider.checkValid;
// ... reset
$scope.form.reset = function (form) {
validationProvider.reset(form);
};
Set the valid/invalid message style CSS
<span><p class="validation-valid">Your valid message here<p></span>
<span><p class="validation-invalid">Your invalid message here<p></span>
.validation-valid {
<!-- valid style -->
}
.validation-invalid {
<!-- invalid style -->
}
Custom the valid/invalid message style HTML in .config()
,
setErrorHTML(func)
setSuccessHTML(func)
, input should be a function
and given parameter
which is the valid/invalid message declared
in getDefaultMsg()
,and finally return the HTML code
// your angular
.config(function ($validationProvider) {
$validationProvider.setErrorHTML(function (msg) {
// remember to return your HTML
// eg: return '<p class="invalid">' + msg + '</p>';
});
$validationProvider.setSuccessHTML(function (msg) {
// eg: return '<p class="valid">' + msg + '</p>';
});
});
Anyone can give a PR
for this angular-validation for more built-in validation
Clone the repo to your computer
git clone https://github.com/huei90/angular-validation.git
Install Grunt and Download dependencies
npm install -g grunt-cli
npm install
Before coding Boot the Environment
grunt dev
Start coding
open `provider.js`, looking for `var expression` and `var defaultMsg`
Adding a new expression and defaultMsg to extend it
IP validation As the example
// provider.js
var expression = {
required: /.+/gi,
... // add new expression below
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
};
var defaultMsg = {
required: {
error: 'This should be Required!!',
success: 'It\'s Required'
},
... // add new valid message below
ip: {
error: 'This isn\'t ip',
success: 'It\'s IP'
}
};
Test
Karma Test done by Travis-ci,
When you are done, test it on `http://localhost:8080`
Give me a PR Thanks for it
Who does the exactly same job ?
Note
FAQs
Client-side Validation for AngularJS
The npm package angular-validation receives a total of 790 weekly downloads. As such, angular-validation popularity was classified as not popular.
We found that angular-validation 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.