Validate JSON against JSON Schema C#

I think that you just need to add ‘additionalProperties’: false to your schema. This will stop unknown properties being provided. So now your results will be:- True, False, False test code…. void Main() { var schema = JsonSchema.Parse( @”{ ‘type’: ‘object’, ‘properties’: { ‘name’: {‘type’:’string’}, ‘hobbies’: {‘type’: ‘array’} }, ‘additionalProperties’: false }”); IsValid(JObject.Parse( @”{ ‘name’: … Read more

Validate an XML file against local DTD file with Java

In an ideal world, you’d be able to validate using a Validator. Something like this: SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.XML_DTD_NS_URI); Schema schema = schemaFactory.newSchema(new File( “xmlValidate.dtd”)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(“xmlValidate.xml”)); Unfortunately, the Sun implementation (at least, as of Java 6) does not include support for creating a Schema instance from a DTD. You … Read more

Remote Validation in ASP.Net MVC 3: How to use AdditionalFields in Action Method

Strange. It works for me: Model: public class MyViewModel { [Required] [Remote(“IsEmailAvailable”, “Home”, AdditionalFields = “InitialEmail”)] public string Email { get; set; } } Controller: public class HomeController : Controller { public ActionResult Index() { return View(new MyViewModel()); } [HttpPost] public ActionResult Index(MyViewModel model) { return View(model); } public ActionResult IsEmailAvailable(string email, string initialEmail) { … Read more

rails built in datetime validation

There’s no built-in ActiveRecord validator for DateTimes, but you can easily add this sort of capability to an ActiveRecord model, without using a plugin, with something like this: class Thing < ActiveRecord::Base validate :happened_at_is_valid_datetime def happened_at_is_valid_datetime errors.add(:happened_at, ‘must be a valid datetime’) if ((DateTime.parse(happened_at) rescue ArgumentError) == ArgumentError) end end

Allowed characters for CSS identifiers

The charset doesn’t matter. The allowed characters matters more. Check the CSS specification. Here’s a cite of relevance: In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a … Read more

Best JavaScript solution for client-side form validation and interaction? [closed]

This is a shameless plug, but might I volunteer a framework that I designed? I’ve built it based on annotations (a la Hibernate Validator). It has support for custom constraints and I feel that it is pretty powerful. Here is also a Stackoverflow question where I asked for a review of the framework. Presentation: With … Read more

Order of Serializer Validation in Django REST Framework

Since most likely your username field has unique=True set, Django REST Framework automatically adds a validator that checks to make sure the new username is unique. You can actually confirm this by doing repr(serializer()), which will show you all of the automatically generated fields, which includes the validators. Validation is run in a specific, undocumented … Read more

Proper validation with MVVM

Warning: Long answer also I use the IDataErrorInfo interface for validation, but I have customised it to my needs. I think that you’ll find that it solves some of your problems too. One difference to your question is that I implement it in my base data type class. As you pointed out, this interface just … Read more

How to add a Not Equal To rule in jQuery.validation

You could use a custom method, something like this: jQuery.validator.addMethod(“notEqual”, function(value, element, param) { return this.optional(element) || value != param; }, “Please specify a different (non-default) value”); Then use it like this: $(“form”).validate({ rules: { nameField: { notEqual: “Your Name” } } }); Adding it as a rule like this makes it more extensible, so … Read more