I have created a #url constraint validation and provided regex. Above it I have annotated #pattern. So, whenever in my bean I am entering value in field url, the url is getting validated
Currently i have a regex which is validating this url. "http://www.google.com".
My new requirement is it should validate only "www.google.com"
I can just change the regex and it will work. but the problem is there are 2 different scenarios
1.In one i need to validate "http://www.google.com"
2.In second i need to validate this "www.google.com"
So, i cannot change the regex. Can anyone please help how can I resolve this? If i need to use custom validator instead of hibernate validator, then how can i achieve this?
I have tried to create
1.custom validator and in isvalid method i am validating the url without #Pattern
2.I have tried #Pattern by changing my regex to just validate domain and path and skip protocol http
Related
I am using the rule object from Laravel 8
artisan make:rule RequireBetweenOf
See https://laravel.com/docs/8.x/validation#using-rule-objects
How do I access other fields or the validator?
I need to check other data in the validator.
I know how it works for for Validator::extend() as 4. parameter but that does not work for Illuminate\Contracts\Validation\Rule. I have also seen that there is a answer using request(). But that is a hack, because validator data and request might not be the same. There might be no request at all.
TL;DR
use Illuminate\Contracts\Validation\ValidatorAwareRule;
use Illuminate\Contracts\Validation\DataAwareRule;
class RequireBetweenOf implements Rule, DataAwareRule, ValidatorAwareRule
I found the password rule is using the validator: \Illuminate\Validation\Rules\Password::setValidator.
Digging deeper this is used here: \Illuminate\Validation\Validator::validateUsingCustomRule.
Key are those two interfaces: \Illuminate\Contracts\Validation\ValidatorAwareRule and \Illuminate\Contracts\Validation\DataAwareRule
I have two fields, one that not allow save HTML tags on DB and the other allow.
How I create an validator that remove spetial chars and tags from my string before save, and apply on String fields only?
PS.: I need something to block SQL inject too.
Actually validator cannot remove any chars. Validator just checks whether entered content is valid or not.
Read for example
For your case you can define form fields and mar them with
#Pattern(regexp = "the detect html expression here")
See regular expressions to [detect][2] (and remove) html
Hello,
I want to understand how to handle data validation with Laravel 5. I see that this can be done using or the validator, or the request files. The thing is that there are many points I didn't get.
What is the difference between using a request file for validation or the validator class ?
If I have validation conditions, and I want to use them only if the concerned field was submitted, how can I do that ? If I use the "required" keyword, it won't work because it will fail when the field is not submitted. If I don't use it, it will accept empty strings...
Thanks ahead !
1. Theoretically there is no difference between Controller validation and Validation using FormRequest. Normally you should use FormRequest. This will keep your controller clean and Minimal. But some time it is sensible to use Validator within controller, e.g you know there is going to be just one field to validate, then it would be overkill to use FormRequest. So it is a matter of preferance.
2. You don't have to use 'required' if the field is not required. Other validation for that field will still run if that field is submitted. If not submitted nothing will happen.
.......
'money' => 'numeric',
.......
Above Rule will make sure that money field is numeric only if it is submitted. If no submitted no validation error will be thrown.
I hope this helps.
Request classes are the better way to validate requests, because
they help to extract this functionality from the constructor method,
which should be as clean as possible.
Use 'sometimes' validator. http://laravel.com/docs/5.1/validation#conditionally-adding-rules
One of my models has a 'url' field. I am using the default url validation rule on it. When trying to add a specific url it is not validated.
The url causing validation to fail is http://careers2.hiredesk.net/ViewJobs/JobDetail.asp?Comp=I3&TP_ID=1&PROJ_ID={BDA01FCD-5703-4D40-9197-CCF688633951}
The { character is causing the validation to fail. What workarounds do I have here?
Do you pass your given URL through a URL Encode Function first? See the linked page for an example.
Products.validation has some validators (like regex) that I would like to use in some non required fields.
So, the use case is: The validation is required, but only if the field is not empty.
How do you do it? I know I can create a custom validator, check the REQUEST and do all the magic, but this seens wrong to me: I should avoid creating custom code since I should just register the RegexValidators from Products.validation and use it. I tried to understand V_SUFFICIENT and register a regex validator using it, but isn't applicable to my situation.
I couldn't find anything on the internet, on mailing lists, on nabble, etc. So, how do you validate your fields that aren't required, but if the user provides something, you then need to validate?
I need this in a Plone 3.3.5 instance.
You can use required = False and your desired validators:
http://plone.org/documentation/manual/developer-manual/archetypes/fields/fields-reference#common-field-attributes