validation

How to use @NotNull with spring boot?

跟風遠走 提交于 2021-02-08 20:00:08
问题 I have this dependency: <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </dependency> Which have it's version managed by <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> And I have this piece: import javax.validation.constraints.NotNull; //other imports ommited @Component @ConfigurationProperties(prefix = "collector") public class

Getting details of binding errors for a JSON form in Spring MVC

北城余情 提交于 2021-02-08 15:57:18
问题 I use Spring MVC 3.2.4. I have a controller method that receives data from an HTML form. The method has the following signature: @RequestMapping(...) public String updateProduct(@Valid Product product, BindingResult bindingResult) In the method, I can get information about both data binding (e.g., a non-integer value in an integer field) and validation (JSR-303) errors in the following way: if (bindingResult.hasErrors()) { List<FieldError> errors = bindingResult.getFieldErrors(); for

Kendo UI, How to manually call validate() on kendo grid cell

China☆狼群 提交于 2021-02-08 15:22:13
问题 Is there a way to call validate() on a cell in kendo-grid without using the editCell() method? the way to invoke validator recommended by the Telerik team is as follows: $("myGrid").data("kendoGrid").editable.validatable.validate() however, no editable object is available if there is no cell open (e.g there is no focused input in the grid), so I have to activate cells one by one to call validate() I would like to invoke validation on each of the grid cells and run some logic (e.g. addClass()

Laravel conditional unique validation

家住魔仙堡 提交于 2021-02-08 15:18:25
问题 Working with Laravel 5.4, I need to validate if the email field on the users table is unique only if the role_id field is not 999. In the Register Controller I did this: return Validator::make($data, [ 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'email' => [ 'required', 'email', 'max:255', Rule::unique('users')->where(function($query) { $query->where('role_id', '<>', 999); }) ], 'phone' => 'required|phone', 'password' => 'required|min:6|confirmed' ]); But when I try

Laravel conditional unique validation

风流意气都作罢 提交于 2021-02-08 15:15:11
问题 Working with Laravel 5.4, I need to validate if the email field on the users table is unique only if the role_id field is not 999. In the Register Controller I did this: return Validator::make($data, [ 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'email' => [ 'required', 'email', 'max:255', Rule::unique('users')->where(function($query) { $query->where('role_id', '<>', 999); }) ], 'phone' => 'required|phone', 'password' => 'required|min:6|confirmed' ]); But when I try

Custom HTML5 form validation errors only happen after first attempt

做~自己de王妃 提交于 2021-02-08 15:14:52
问题 The below code allows my client to create a custom form with different types of fields and then allows their clients to fill that form in and submit it somewhere. Basically, a custom form builder for Wordpress. I have successfully replaced the custom behavior for the HTML5 form validation error messages using the below code. However, the custom message I have set for the different types of form fields only appear the 2nd time the form submit is attempted. The first time the submit button is

Using regex to restrict input in textbox [duplicate]

房东的猫 提交于 2021-02-08 10:44:20
问题 This question already has answers here : HTML input that takes only numbers and the + symbol (7 answers) Closed 3 years ago . /^+{0,1}(?:\d\s?){11,13}$/ this regex allows + at first place only and numbers only... on keypress I want user should only be able to type + at first and digits that what above regex validates But code always goes to if part..why regex not working in this scenario function ValidatePhone(phone) { var expr = /^\+?(?:\d\s?){11,13}$/; return expr.test(phone); } var

Using regex to restrict input in textbox [duplicate]

你。 提交于 2021-02-08 10:43:01
问题 This question already has answers here : HTML input that takes only numbers and the + symbol (7 answers) Closed 3 years ago . /^+{0,1}(?:\d\s?){11,13}$/ this regex allows + at first place only and numbers only... on keypress I want user should only be able to type + at first and digits that what above regex validates But code always goes to if part..why regex not working in this scenario function ValidatePhone(phone) { var expr = /^\+?(?:\d\s?){11,13}$/; return expr.test(phone); } var

Trix editor validation

一曲冷凌霜 提交于 2021-02-08 09:10:40
问题 Using Trix editor via Rails view helpers. = form.rich_text_area :description, class: 'form-control', placeholder: 'Description' Have some model 'required' validation for description. The normal Rails behavior of wrapping fields with field_with_errors is not happening. Has anyone managed to get Trix and the normal Rails validation behavior to work together? 回答1: Ended up fixing this way.. - if job.errors[:description].count > 0 .form-with-errors = form.rich_text_area :description, class: 'form

Springboot国际化信息(i18n)解析

别来无恙 提交于 2021-02-08 07:37:56
国际化信息理解 国际化信息也称为本地化信息 。 Java 通过 java.util.Locale 类来表示本地化对象,它通过 “语言类型” 和 “国家/地区” 来创建一个确定的本地化对象 。举个例子吧,比如在发送一个具体的请求的时候,在header中设置一个键值对:"Accept-Language":"zh",通过Accept-Language对应值,服务器就可以决定使用哪一个区域的语言,找到相应的资源文件,格式化处理,然后返回给客户端。 MessageSource Spring 定义了 MessageSource 接口,用于访问国际化信息。 getMessage(String code, Object[] args, String defaultMessage, Locale locale) getMessage(String code, Object[] args, Locale locale) getMessage(MessageSourceResolvable resolvable, Locale locale) MessageSourceAutoConfiguration springboot提供了国际化信息自动配置类,配置类中注册了ResourceBundleMessageSource实现类。 1 @Configuration 2