How to validate not blank values in Access Data Validation - validation

I'm just wondering if there is a way in Access Data Validation to run if and only if the fields they are validating are not blank? In other words, do not run data validation if the corresponding fields are blank?
Must I insert an if expression before the data validation rule to do so?

Related

Can Laravel model validate the field data types(int,float,..etc) while inserting data?

My problem is that I'm using noSql for my database and Laravel for the backend.
I know that we can validate the data types in the request but this validates only the incoming request after that we might calculate or re-arrange the data type of a field and insert it. I want to prevent this insertion by checking the data types. Is there a way to implement this validation in model like fillable [] or casts [].
You could setup an Observer on that model and in the Observer's 'updating' method you could perform any type formatting or cleanup required.
Or if it's a real edge case you could call the Validator facade to define the keys/rules to check for and then pass your changed object to it? If Validator->fails() you could loop through Validator->errors() and apply corrections as needed.

How to check thrown errors during Sequelize validation execution

I have a sequelize model, which needs custom validation. That custom validation relies on some foreign keys being valid (valid as in valid uuid, not checked that they exist in db) on a record. There is also another validator appended that checks for mutual exclusivity of the foreign keys (only one can be present at the same time). After all this, I access the database in another validator to fetch data from another collection. I dont want this to happen if any of above validators fail because I dont want to access the database if I dont have to and I dont want to check if uuid is valid again because that is a job for one of previous validators.
The order is like so:
check if field contains valid type (uuid) - field type validator
check that field is not clashing with another field (mutually exclusive) - model-wide validator
fetch record from another collection to do further validation - model-wide validator
I want to check if previous validator has already thrown an error and not execute the next one if it has. Even better if I can check which one has thrown an error. Sequelize executes all validators even if error was already thrown. In documentation it says:
Any error messages collected are put in the validation result object
alongside the field validation errors, with keys named after the
failed validation method's key in the validate option object. Even
though there can only be one error message for each model validation
method at any one time, it is presented as a single string error in an
array, to maximize consistency with the field errors.
I tried several ways to access this "error" object but to no avail. Is there a way at all to know if error was already thrown by one of previous validators?

Laravel form request check if two passwords match?

I am working on a user registration form in laravel 5. I wish to know is it possible to use laravel's form request validation to check if the two passwords submitted by the user are thesame. Is it possible to do that with using requests?
Yes, it's possible.
There is an validator called confirmed.
confirmed
The field under validation must have a matching field of
foo_confirmation. For example, if the field under validation is
password, a matching password_confirmation field must be present in
the input.
https://laravel.com/docs/5.2/validation#rule-confirmed

JSR 303 - Validate a field if it is not null

I have a form which is filled in, and some of the fields are options. I want to apply validations on the information that was filled in but the optional fields should be validated only if there was something filled in, so if theses are not null. Did any of you do something similar?
Or do you have any suggestion?
Bean Validation constraints usually accept null as valid value (with the exception of #NotNull of course). Depending on your UI framework you might retrieve empty strings instead of null for fields without user input. If you're are working with JSF 2, you can set the context parameter javax.faces.VALIDATE_EMPTY_FIELDS to false to avoid a validation of empty fields.

Custom Data Annotation Attribute using Metadata

My requirement is to create a custom data annotation attribute for my project. The requirement is to validate the min/ max length of a specific product from the database, which will be retrieved from the database using the ProductID. I have a dynamic page for each product where there are two fields called max length & min length. User inputs the values in these two fields which needs to be validated from the database. Product table contains all the products & one will be selected by passing a productId.
Please suggest some pointers to implement the above.
Thanks in advance.
This validation you can do only in the server side and not in client, so I see two options.
Remote Validation - You can use remote validation when you want to perform the validation and show the error message through ajax.
IValidatableObject - By implementing this interface in the class you can do both the validations at the same time and return all the validation error messages as a collection. By this way the validation will happen after the form is normally submitted.

Resources