Declaring string type with min/max length in typescript

You can achieve this using a type constructor and something called a “Phantom Type” (read a nice article about this here) which is a technique to ensure that a type can not be assigned to a value directly. Here’s an example of a StringOfLength<Min,Max> type using these techniques: type StringOfLength<Min, Max> = string & { … Read more

Why is my Spring 3 Validator Validating Everything on the Model?

I guess this behaviour is not covered in the documentation well. The problem is caused by the following: By default, @InitBinder-annotated method is called for each non-primitive model attribute, both incoming and outcoming (the purpose of calling it for outcoming attibutes is to allow you to register custom PropertyEditors, which are used by form tags … Read more

Credit Card validation: can Card Name contain non-ASCII characters?

The character set that is used does not allow for diacritics. In brief, it only allows uppercase ASCII characters. The restriction ultimately comes from the historical way in which banking cards encode data onto the magnetic stripe (as defined in ISO 7811). The data is encoded in a 7 bits per character format known as … Read more

How can I sanitize a string for use as a filename?

You can use PathGetCharType function, PathCleanupSpec function or the following trick: function IsValidFilePath(const FileName: String): Boolean; var S: String; I: Integer; begin Result := False; S := FileName; repeat I := LastDelimiter(‘\/’, S); MoveFile(nil, PChar(S)); if (GetLastError = ERROR_ALREADY_EXISTS) or ( (GetFileAttributes(PChar(Copy(S, I + 1, MaxInt))) = INVALID_FILE_ATTRIBUTES) and (GetLastError=ERROR_INVALID_NAME) ) then Exit; if I>0 … Read more

Using redux-form I’m losing focus after typing the first character

This happens because you’re re-defining renderField as a new component every time you render which means it looks like a new component to React so it’ll unmount the original one and re-mounts the new one. You’ll need to hoist it up: const renderField = ({ input, label, type, meta: { touched, invalid, error } }) … Read more

Modify default ErrorMessage for StringLength validation

You can specify the StringLength attribute as follows on numerous properties [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string OfficePhone { get; set; } [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string CellPhone { get; set; } and add the string resource (named StringLengthMessage) in your resource file “Maximum length is {1}” Message … Read more

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