
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
aspnet-validation
Advanced tools
Enables ASP.NET Core MVC client-side validation, without JQuery!
Enables ASP.NET Core MVC client-side validation, without JQuery!
npm install aspnet-validation es6-promise
aspnet-validation uses Promise API, which is not supported in Internet Explorer. It is recommended to use promise-polyfill or es6-promise to resolve this issue...
Alternatively, download these:
<script src="es6-promise.auto.min.js"></script>
<script src="aspnet-validation.min.js"></script>
// Exposes window['aspnetValidation']
var v = new aspnetValidation.ValidationService();
v.bootstrap();
require('es6-promise').polyfill();
const aspnetValidation = require('aspnet-validation');
let v = new aspnetValidation.ValidationService();
v.bootstrap();
import * as ES6Promise from 'es6-promise';
import { ValidationService } from 'aspnet-validation';
ES6Promise.polyfill();
let v = new ValidationService();
v.bootstrap();
Shameless self-promotion: use instapack for painless web application client development using TypeScript!
jQuery + jQuery Validation + jQuery Validation Unobtrusive: 67.9 KB + 22.5 KB + 5.14 KB = 95.6 KB
aspnet-validation: 9.81 KB (10.26%)
git clone https://github.com/ryanelian/aspnet-validation.git
npm install
npm run build # If using PowerShell: .\build.ps1
Example stolen from https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation
public class ClassicMovieAttribute : ValidationAttribute, IClientModelValidator
{
private int _year;
public ClassicMovieAttribute(int Year)
{
_year = Year;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
Movie movie = (Movie)validationContext.ObjectInstance;
if (movie.Genre == Genre.Classic && movie.ReleaseDate.Year > _year)
{
return new ValidationResult(GetErrorMessage());
}
return ValidationResult.Success;
}
public void AddValidation(ClientModelValidationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-classicmovie", GetErrorMessage());
var year = _year.ToString(CultureInfo.InvariantCulture);
MergeAttribute(context.Attributes, "data-val-classicmovie-year", year);
}
}
import { ValidationService } from 'aspnet-validation';
let v = new ValidationService();
// Must be done BEFORE bootstrap() is called!
v.addProvider('classicmovie', (value, element, params) => {
if (!value) {
// Let [Required] handle validation error for empty input...
return true;
}
// data-val-classicmovie-year is bound automatically to params!
let year = parseInt(params.year);
let date = new Date(value);
let genreDropdown = document.getElementById('Genre') as HTMLSelectElement;
let genre = select.options[select.selectedIndex].value;
if (genre && genre.length > 0 && genre === '0') {
return date.getFullYear() <= year;
}
return true;
});
v.bootstrap();
Other than boolean
and string
, addProvider
callback accepts Promise<string | boolean>
as return value:
v.addProvider('io', (value, element, params) => {
if (!value) {
return true;
}
return async () => {
let result: number = await Some_IO_Operation(value);
return result > 0;
};
});
FAQs
Enables ASP.NET MVC client-side validation, without jQuery!
The npm package aspnet-validation receives a total of 168 weekly downloads. As such, aspnet-validation popularity was classified as not popular.
We found that aspnet-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
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.