
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
popup-validation
Advanced tools
Pure JavaScript/CSS library for validating DOM input fields
npm install popup-validation --save
Read API
HTML
<link href="validation.css" rel="stylesheet">
<script src="validation.min.js"></script>
<div>
<label for="email">Email:</label>
<input type="email" id="email" class="validate"
data-validate="required,email" />
</div>
JS
Initialization
<body>
validation.init();
Submit
event will be prevented if there are any errorsvalidation.init("#myForm");
validation.init("#myForm", {
events: ["change", "paste", "keyup"]
});
Usage
// Show errors
validation.highlight();
// Hide errors
validation.hide();
// Check if container is valid (body by default)
validation.isValid();
// Check if cotnainer is valid (body by default) + highlight
validation.validate();
Some services like Braintree use iframes to control the inputs on a page. That also can be useful if some javascript logic sets and removes a certain class to/from a div or input field that indicates that the field is not validated.
HTML
<div id="customClassValidation" class="validate-class">
Click at me to toggle custom class validation
</div>
JS
validation.addClassValidation(".my-class-invalid");
// Test
document.getElementById("customClassValidation").addEventListener("click", e => {
e.target.classList.toggle(".my-class-invalid");
});
The set of rules can be easily extended. Please take a look at the example
self
Initialize the validation fields inside of the el
container. If el
is a <form>
element then submit event will be prevented if there are any errors
Returns: object
- Self validation instance for chain calls
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
options | Object | [Optional] Set of the properties |
Default Options
{
events: ["change", "paste", "blur", "keyup"]
}
Affects all input fields with validate
class
data-validate
attr can contain the list of the rules
Example:
<input class="validate" data-validate="required" />
<input type="email" class="validate" data-validate="required,email" />
self
Deactivate the validation fields inside of the el
container
Returns: object
- Self validation instance for chain calls
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
self
Hide all errors inside of the el
container
Returns: object
- Self validation instance for chain calls
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
self
Highlight all errors inside of the el
container
Returns: object
- Self validation instance for chain calls
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
boolean
Check if all input fields inside of the el
container are valid
Returns: boolean
- True if all input fields inside of the container are valid
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
boolean
Validate all input fields inside of the el
container
Returns: boolean
- True if all input fields inside of the container are valid
Param | Type | Description |
---|---|---|
el | Element | Container or <form> Element |
object
The set of the predefined rules
el => boolean
Param | Type | Description |
---|---|---|
el | Element | input field |
Returns: boolean
- True if the field is validated
JS
validation.rules["integer"] = {
message: "Value is not an integer",
method: el => {
return el.value.length === 0 || !isNaN(parseInt(el.value, 10));
}
}
HTML
<input class="validate" data-validate="required,integer" />
self
Add class validation. For external libraries that can set/remove className of the element. For instance, braintree-hosted-fields-invalid class is set by braintree client library when iframe with the input field detects an error, More info here: https://developers.braintreepayments.com/guides/hosted-fields/styling/javascript/v2
Returns: object
- Self validation instance for chain calls
Param | Type | Description |
---|---|---|
selector | string | Selector that indicates that the field is invalid |
![]() IE / Edge | ![]() Firefox | ![]() Chrome | ![]() Safari | ![]() Opera | ![]() iOS Safari | ![]() Chrome for Android |
---|---|---|---|---|---|---|
IE9+ | last 12 versions | last 10 versions | last 15 versions | last 14 versions | last 12 versions | last 13 versions |
MIT
FAQs
Pure JavaScript/CSS library for validating DOM input fields
The npm package popup-validation receives a total of 8 weekly downloads. As such, popup-validation popularity was classified as not popular.
We found that popup-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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.