Spring-Boot How to properly inject javax.validation.Validator

You need to declare a bean of type LocalValidatorFactoryBean like this: <bean id=”validator” class=”org.springframework.validation.beanvalidation.LocalValidatorFactoryBean”/> in XML or @Bean public javax.validation.Validator localValidatorFactoryBean() { return new LocalValidatorFactoryBean(); } in Java Config. Edit: It is important to understand that if JPA is being used and is backed by Hibernate, then Hibernate will try to automatically validate your Beans … Read more

Call MVC 3 Client Side Validation Manually for ajax posts

Try: //using the form as the jQuery selector (recommended) $(‘form’).submit(function(evt) { evt.preventDefault(); var $form = $(this); if($form.valid()) { //Ajax call here } }); //using the click event on the submit button $(‘#buttonId’).click(function(evt) { evt.preventDefault(); var $form = $(‘form’); if($form.valid()) { //Ajax call here } }); This should work with jQuery ajax and MSAjax calls. Could … Read more

Email model validation with DataAnnotations and DataType

DataType attribute is used for formatting purposes, not for validation. I suggest you use ASP.NET MVC 3 Futures for email validation. Sample code: [Required] [DataType(DataType.EmailAddress)] [EmailAddress] public string Email { get; set; } If you happen to be using .NET Framework 4.5, there’s now a built in EmailAddressAttribute that lives in System.ComponentModel.DataAnnotations.EmailAddressAttribute.

Class-validator – validate array of objects

Add @Type(() => AuthParam) to your array and it should be working. Type decorator is required for nested objects(arrays). Your code becomes import { IsArray, ValidateNested, ArrayMinSize, ArrayMaxSize } from ‘class-validator’; import { AuthParam } from ‘./authParam.model’; import { Type } from ‘class-transformer’; export class SignInModel { @IsArray() @ValidateNested({ each: true }) @ArrayMinSize(2) @ArrayMaxSize(2) @Type(() … Read more

Laravel: Validate maximum File size?

According to the documentation: $validator = Validator::make($request->all(), [ ‘file’ => ‘max:500000’, ]); The value is in kilobytes, for example: max:10240 = max 10 MB. max:1 = max 1024 bytes. Note that there are efforts to change the value of 1 kilobytes from original 1024 to 1000 bytes, but major frameworks like Laravel remain using original … Read more

Django’s ModelForm unique_together validation

I solved this same problem by overriding the validate_unique() method of the ModelForm: def validate_unique(self): exclude = self._get_validation_exclusions() exclude.remove(‘problem’) # allow checking against the missing attribute try: self.instance.validate_unique(exclude=exclude) except ValidationError, e: self._update_errors(e.message_dict) Now I just always make sure that the attribute not provided on the form is still available, e.g. instance=Solution(problem=some_problem) on the initializer.