
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
slim-validation
Advanced tools
Lightweight jQuery validation plugin.
node: npm install slim-validation :sparkling_heart:
git: git clone https://github.com/andreiduca/slim-validation.git
or download the ZIP archive, extract and use the files from the /src folder. See /demo/index.html for a quick implementation.
HTML-only setup required. Just set the "data-validate" custom attribute on your inputs and you're ready to go:
<input type="text" data-validate="required" />
Chain multiple validation rules using the empty space as a delimiter:
<input type="text" data-validate="required email" />
The validation action is triggered by default on the "blur" event on each input.
After each validation, a custom event is triggered so you can bind your own behavior to it, like this:
$('body').on('validation:end', '[data-validate]', function(event, $input, value, isValid, errorMessage) {
// ... your code goes here
});
Notice the parameters you can use at your own disposal. Use your imagination!
In the demo HTML I only added a colored border and error message after each input to highlight its status:
$('body').on('validation:end', '[data-validate]', function(event, $input, value, isValid, errorMessage) {
$input.next('span').remove();
if (!isValid) {
$input.after('<span style="color:red;">' + errorMessage + '</span>');
$input.css({"border": "1px solid red"});
}
else {
$input.after('<span style="color:green;">data is valid</span>');
$input.css({"border": "1px solid green"});
}
});
Note: $input is a jQuery wrapper of the actual input being validated.
Error messages are also defined with custom "data-" attributes:
<input type="text" data-validate="required" data-error="invalid data" />
Custom error messages for each validation rule can also be defined:
<input type="text" data-validate="required email"
data-error="generic error"
data-error-email="Invalid email" />
This is great for internationalized websites where you need translated error messages, and works best with template engines such as smarty or twig. Yes: no more javascript files filled with translated messages!
Some rules require a configurable parameter, like a number to compare against. It's simple: just add the number after that rule:
<input type="text" data-validate="minLength 3" />
More rules for the same input? Just chain them as usual.
(This is a work in progress)
required: the value must not be an empty string;requiredBy: the value must not be empty only if a related input is not empty;numeric: the value must contain only digits;integer: the value must be a valid integer (negative values allowed);min: the value must be an integer greater than or equal to the provided parameter;max: the value must be an integer lower than or equal to the provided parameter;range: the value must be an integer in the range provided using the format 1..10;number: the value must match one of the following number formats: -12345.6789, -12345,6789, -12,345.6789, -12.345,6789 (the negative sign and the fractional part are optional);minLength: the value's length must be more than or equal to the provided parameter;maxLength: the value's length must be less than or equal to the provided parameter;email: the value must match a "practical RFC 5322" regex: (see http://www.regular-expressions.info/email.html)FAQs
Lightweight jQuery validation plugin.
We found that slim-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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.