@thinknpm/vanilla-validation
Vanilla JavaScript validation rules
Usage
Use in a plain project:
<script src="./path-to/vanilla-validation.umd.js"></script>
<script>console.log(vRules);</script>
Use in a node enviroment
Install the package from npm:
npm install --save @thinknpm/vanilla-validation
Include the package
const vRules = require('@thinknpm/vanilla-validation')
console.log(vRules);
Validate an input:
<input type="email" id="email" value="test@example.com">
var emailElm = document.getElementById('email');
vRules.vrule_email(emailElm)
console.log(vRules.vrule_email(emailElm))
Rules available
vrule_required(elm, customMessage)
vrule_requiredIf(elm, validator, customMessage)
vrule_checkboxTrue(fieldset, customMessage)
vrule_btn_required(fieldset, customMessage)
vrule_textInput(elm, customMessage)
vrule_numberInput(elm, customMessage)
vrule_minLength(elm, min, customMessage)
vrule_maxLength(elm, max, customMessage)
vrule_minValue(elm, min, customMessage)
vrule_maxValue(elm, max, customMessage)
vrule_date(date, customMessage)
vrule_date_required(date, customMessage)
vrule_notBeforeX(elm, dateCheck, customMessage)
vrule_ageRange(date, ageRange, customMessage)
vrule_minAge(date, minAge, customMessage)
vrule_mobileNumber(elm, customMessage)
vrule_homeNumber(elm, customMessage)
vrule_anyPhone(elm, customMessage)
vrule_email(elm, customMessage)
vrule_currency(elm, customMessage)
vrule_postcode(elm, customMessage)