Validate a hostname string

import re def is_valid_hostname(hostname): if len(hostname) > 255: return False if hostname[-1] == “.”: hostname = hostname[:-1] # strip exactly one dot from the right, if present allowed = re.compile(“(?!-)[A-Z\d-]{1,63}(?<!-)$”, re.IGNORECASE) return all(allowed.match(x) for x in hostname.split(“.”)) ensures that each segment contains at least one character and a maximum of 63 characters consists only of … Read more

Spring MVC validator annotation + custom validation

I know this is a kind of old question but, for googlers… you should use addValidators instead of setValidator. Like following: @InitBinder protected void initBinder(final WebDataBinder binder) { binder.addValidators(yourCustomValidator, anotherValidatorOfYours); } PS: addValidators accepts multiple parameters (ellipsis) if you checkout the source of org.springframework.validation.DataBinder you will see: public class DataBinder implements PropertyEditorRegistry, TypeConverter { …. … Read more

An invalid regex pattern

This is invalid… [ You can also test the validity of regular expressions in real-time at http://regexhero.net/tester/ By the way, you don’t actually have to test the regular expression against a string to see if it’s valid. You can simply instantiate a new Regex object and catch the exception. This is what Regex Hero does … Read more

How to fix Expected start-union. Got VALUE_NUMBER_INT when converting JSON to Avro on the command line?

According to the explanation by Doug Cutting, Avro’s JSON encoding requires that non-null union values be tagged with their intended type. This is because unions like [“bytes”,”string”] and [“int”,”long”] are ambiguous in JSON, the first are both encoded as JSON strings, while the second are both encoded as JSON numbers. http://avro.apache.org/docs/current/spec.html#json_encoding Thus your record must … Read more

How to prevent user pasting text in a textbox?

Very Easy Solution: <input name=”ReceiveNo” type=”text” class=”txtbox” onkeypress=”validate(event)” maxlength=”11″ value=”${cpCon.receiveNo}” required tabindex=”34″ onCopy=”return false” onDrag=”return false” onDrop=”return false” onPaste=”return false” autocomplete=off /> This worked for me very well. No one can paste now into your textbox using right button paste option of mouse or pressing ctrl+v from the keyboard.

validate nested objects using class-validator in nest.js controller

Try specifying the nested type with @Type: import { Type } from ‘class-transformer’; export class CurrencyDTO { @ValidateNested({ each: true }) @Type(() => Data) data: Data[]; } For a nested type to be validated, it needs to be an instance of a class not just a plain data object. With the @Type decorator you tell … Read more

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