Number in the top-level domain?

Does top-level domain can contain a number at the end? Yes technically, except if it is purely numerical, then it can not be a TLD, under current rules and for easy reasons to understand (to disambiguate with IP addresses). And it can not contain a number at the end, except if it is an IDN … Read more

Why are Exceptions said to be so bad for Input Validation?

Reading these answers, I find it very unhelpful to say, “Exceptions should only be used for exceptional conditions”. This begs the whole question of what is an “exceptional condition”. This is a subjective term, the best definition of which is “any condition that your normal logic flow doesn’t deal with”. In other words, an exceptional … Read more

Joi Validations: If object matches the schema validate against it from multiple items

There are some typos in your files and validators. First of Joi.array is a function and needs to be called as one. // This is incorrect data2: Joi.array … additional: Joi.array // Should be changed to this where array is invoked as a function data2: Joi.array() … additional: Joi.array() Additionally, I’ve added a fourth validator … Read more

Validating for large files upon Upload

One possibility is to write a custom validation attribute: public class MaxFileSizeAttribute : ValidationAttribute { private readonly int _maxFileSize; public MaxFileSizeAttribute(int maxFileSize) { _maxFileSize = maxFileSize; } public override bool IsValid(object value) { var file = value as HttpPostedFileBase; if (file == null) { return false; } return file.ContentLength <= _maxFileSize; } public override string … Read more

Is it possible to validate the size and type of input=file in html5

<form class=”upload-form”> <input class=”upload-file” data-max-size=”2048″ type=”file” > <input type=submit> </form> <script> $(function(){ var fileInput = $(‘.upload-file’); var maxSize = fileInput.data(‘max-size’); $(‘.upload-form’).submit(function(e){ if(fileInput.get(0).files.length){ var fileSize = fileInput.get(0).files[0].size; // in bytes if(fileSize>maxSize){ alert(‘file size is more then’ + maxSize + ‘ bytes’); return false; }else{ alert(‘file size is correct- ‘+fileSize+’ bytes’); } }else{ alert(‘choose file, please’); return … Read more

Validate order of items inside ui:repeat

There’s physically only one UIInput component whose state changes depending on the current iteration round of UIRepeat. It’s available by just its client ID without the UIRepeat index: findComponent(“formId:inputId”) (the UIRepeat index is only of significance in the client side). However, when the component is programmatically been accessed outside the context of UIRepeat this way, … Read more

Why does setting ng-model to undefined not make the form/input valid again?

Whenever you use ng-model on an input or select tag, angular internally manages two values for the field, one is $viewValue and other is $modelValue $viewValue -> Used for display purpose on view $modelValue-> Actual value which is used inside scope. When using an input tag with type=”email” Angular constantly validates the input value. And … Read more

Autowired Repository is Null in Custom Constraint Validator

Which ValidatorFactory are you using. Or to put it another way, hot to you bootstrap Bean Validation? Per default Bean Validation (and Hibernate Validator as reference implentation) does not inject dependencies into ConstraintValidator instances. At least in Bean Validation 1.0. To enable dependency injection you have to configure a custom ConstraintValidatorFactory. Spring offers SpringConstraintValidatorFactory which … Read more

Which function in php validate if the string is valid html?

Maybe you need to check if the string is well formed. I would use a function like this function check($string) { $start =strpos($string, ‘<‘); $end =strrpos($string, ‘>’,$start); $len=strlen($string); if ($end !== false) { $string = substr($string, $start); } else { $string = substr($string, $start, $len-$start); } libxml_use_internal_errors(true); libxml_clear_errors(); $xml = simplexml_load_string($string); return count(libxml_get_errors())==0; } Just … Read more

Conditionally provide either file download or show export validation error message

Is there any generally acceptable way of solving issues like this one? You basically want to fire an ajax request first and in its oncomplete check if it’s successful, and then trigger a synchronous request to download the file (note that you can’t download files with ajax). You could make use of FacesContext#validationFailed() (or OmniFaces … Read more