Is there a way to know if a Java program was started from the command line or from a jar file?

The straight forward answer is that you cannot tell how the JVM was launched. But for the example use-case in your question, you don’t really need to know how the JVM was launched. What you really need to know is whether the user will see a message written to the console. And the way to … Read more

How can I access the collection item being validated when using RuleForEach?

Currently there are no functionality in FluentValidation, that allows to set validation state the way you want. RuleForEach was designed to prevent creation of trivial validators for simple collection items, and it’s implementation didn’t cover all possible use cases. You can create separate validator class for Order and apply it using SetCollectionValidator method. To access … Read more

Angular ng-repeat with ng-form, accessing validation in controller

Updated 2015-01-17: As pointed out by Leblanc Meneses in the comments Angular 1.3 now supports interpolation with form, ngForm and input directives. This means that using expressions to name your elements: <div ng-form=”namesForm_{{$index}}” ng-repeat=”name in names”> <input type=”text” name=”input_{{$index}}_0″></input> <!– … –> </div> will work as expected: $scope[‘namesForm_0’] $scope.namesForm_1 // Access nested form elements: $scope.namesForm_1.input_1_0 … Read more

Angular 2 custom validator with parameters

Here is a sample. It’s a min value validator where you pass in a number to validate. import {Control} from ‘angular2/common’; export const minValueValidator = (min:number) => { return (control:Control) => { var num = +control.value; if(isNaN(num) || num < min){ return { minValue: {valid: false} }; } return null; }; }; More details can … Read more

How to change the ErrorMessage for int model validation in ASP.NET MVC?

Yes, you can use Data annotations extensions, mark your property as the following: [Required(ErrorMessage = “Please enter how many Stream Entries are displayed per page.”)] [Range(0, 250, ErrorMessage = “Please enter a number between 0 and 250.”)] [Column] [DataAnnotationsExtensions.Integer(ErrorMessage = “Please enter a valid number.”)] public int StreamEntriesPerPage { get; set; }

Check if a date string is in ISO and UTC format

Try this – you need to actually create a date object rather than parsing the string NOTE: This will test the string AS YOU POSTED IT. YYYY-MM-DDTHH:MN:SS.MSSZ It will fail on valid ISO8601 dates like Date: 2018-10-18 Combined date and time in UTC: 2018-10-18T08:04:30+00:00 (without the Z and TZ in 00:00) 2018-10-18T08:04:30Z 20181018T080430Z Week: 2018-W42 … Read more

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

Rails: how to require at least one field not to be blank

You can use: validate :any_present? def any_present? if %w(field1 field2 field3).all?{|attr| self[attr].blank?} errors.add :base, “Error message” end end EDIT: updated from original answer for Rails 3+ as per comment. But you have to provide field names manually. You could get all content columns of a model with Model.content_columns.map(&:name), but it will include created_at and updated_at … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)