
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
js-form-validator
Advanced tools
Js Form Validation - Package for simplify form validation =========================================================
Js Form Validation is a simple package to validate your forms. This package works with standard js form API, so you can use any error message customisation library (or write own realization) with it.
npm
npm install js-form-validation --save
There are two ways to include js-form-validator in your project:
<script src="node_modules/js-form-validator/dist/form-validator.min.js"></script>
import formValidator from 'js-form-validator';
or
var formValidator = require('js-form-validator');
if you use es5 syntax
Js Form Validation has 2 methods only:
set your validation rules to your form
####Parameters
formName Type: String your html form name.
rules Type: Object An object with validation rules. (See Config Object section)
formValidator.setFormValidation('userRegistrationForm', registrationFormRules);
add custom form validator
####Parameters:
validatorName Type: String name of your validator (example: 'passwordConfirmation').
callback Type: Function your validator function.
Notice:
your validator function should has the following structure:
function validator(fieldValue, data, firstBindedFoueldValue, secondBoundedFieldValue, ....) {
// your check. Must return true or false
}
where:
if you didn't specify 'data' in config object, you still must provide data parameter in your function!
Example:
our favorite password confirmation validator :)
formValidator
.addValidator('confirmPassword', function (passwordConfirmation, data, originalPassword) {
return passwordConfirmation === originalPassword
});
Config object has the following structure:
[{
name: 'firstFieldName',
rules: [{
name: 'ruleName',
message: 'error message',
data: 'additional data',
bindWith: ['secondFieldName']
}, {
...
}]
}, {
name: 'secondFieldName',
rules: [...]
}];
where each field is an object in list. it has 2 properties:
Each rule in rules array has:
Also rule can two additional properties:
NOTICE: each field in config object must have named like in your html file
Example:
// simple registration form rules scheme
var registrationFormScheme = [{
name: 'userLogin',
rules: [{
name: 'required',
message: 'field is required'
}, {
name: 'minLength',
message: 'login is too short',
data: 5
}, {
name: 'maxLength',
message: 'login is too long',
data: 12
}]
}, {
name: 'userPassword',
rules: [{
name: 'required',
message: 'field is required'
}, {
name: 'minLength',
message: 'password is too short',
data: 5
}]
}, {
name: 'userPasswordConfirmation',
rules: [{
name: 'required',
message: 'field is required'
}, {
name: 'confirmPassword',
bindWith: ['userPassword'],
message: 'please, repeat your password'
}]
}];
this config object represents following web form
<form name="userRegistrationForm" action="" id="userRegistrationForm" class="col-md-5 offset-md-5">
<input name="userLogin" id="userLogin" type="text" class="form-control" placeholder="login">
<input name="userPassword" id="userPassword" type="password" class="form-control" placeholder="password">
<input name="userPasswordConfirmation" id="userPasswordConfirmation" type="password" class="form-control" placeholder="password confirmation">
<button class="btn bg-primary submit-btn">Submit</button>
</form>
Notice: default js form validator has following validators:
You can find example of usage js-form-validator in 'example' folder. you must execute the following commands to run example:
npm install
npm start
Example will be available on http://localhost:4000/
FAQs
Js Form Validation - Package for simplify form validation =========================================================
We found that js-form-validator 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.