Skip to content

Instantly share code, notes, and snippets.

@Crydust
Last active March 28, 2022 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crydust/a1935014e755731611f938ceb783e52c to your computer and use it in GitHub Desktop.
Save Crydust/a1935014e755731611f938ceb783e52c to your computer and use it in GitHub Desktop.
dotnet webapp validation config
<script src="~/lib/jquery-validate/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@if (",".Equals(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
{
<script>
// decimal separator comma instead of point
jQuery.extend(jQuery.validator.methods, {
number: function(value, element) {
return this.optional(element) || /^-?\d+(?:,\d+)?$/.test(value);
},
min: function(value, element, param) {
return this.optional(element) || value.replace(/,/g, '.') >= param;
},
max: function(value, element, param) {
return this.optional(element) || value.replace(/,/g, '.') <= param;
},
range: function(value, element, param) {
if (this.optional(element)) {
return true;
}
value = value.replace(/,/g, '.');
return (value >= param[0] && value <= param[1]);
}
});
</script>
}
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "bootstrap@5.1.3",
"destination": "wwwroot/lib/bootstrap/"
},
{
"library": "jquery@3.6.0",
"destination": "wwwroot/lib/jquery/",
"files": [
"jquery.min.js",
"jquery.js",
"jquery.min.map"
]
},
{
"library": "jquery-validation-unobtrusive@3.2.12",
"destination": "wwwroot/lib/jquery-validation-unobtrusive/"
},
{
"library": "jquery-validate@1.19.3",
"destination": "wwwroot/lib/jquery-validate/"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment