Laravel 5.5 validation if checkbox is check and then validation on some field - laravel-5.5

I am new in Laravel I want to need some validation if I checked checkbox then in front of input field will validate Required|Numeric|min:1
Please Help.
As per below image

You are looking for required_if.
So, you could have the following rules in your Form Request or your Validator.
return [
'systolic_blood_pressure_high' => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
'systolic_blood_pressure_low' => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
];
Assuming you have a checkbox with name has_systolic_bp and it is checked, the fields systolic_blood_pressure_high and systolic_blood_pressure_low will be required.
You also need to mark them as nullable as by default Laravel will consider them as invalid because of the TrimStrings and ConvertEmptyStringsToNull middlewares.
For more information, check the documentation

Related

in loopback model.json file how to give validations

In model.json file I try to give validation property to array as per document says but it doesn't work .. (I want validaions by validations prperty only)
How to give validations array ?..
also see i tried as per in screenshort but that didn't workenter image description here
I am new to Loopback but the current (v3) documentation states:
Warning: This is not yet implemented. You must currently validate in
code; see Validating model data.
For now you have to put your validation code in the model's JS file.
This is the example given in the documentation:
common/models/user.js
module.exports = function(user) {
user.validatesPresenceOf('name', 'email');
user.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
user.validatesInclusionOf('gender', {in: ['male', 'female']});
user.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
user.validatesNumericalityOf('age', {int: true});
user.validatesUniquenessOf('email', {message: 'email is not unique'});
};
This is reminiscent of Angular's Reactive form validation.

Vue.js - Element UI - Form validation regexp

I'd like to validate a form using vue-js 2.3 and element-ui
Apparently, they use async-validator to validate the form. The documentation is here.
Example
https://jsfiddle.net/skd3nyqh/
Problem
Uncaught Error: Unknown rule type D*([2-9]d{2})(D*)([2-9]d{2})(D*)(d{4})D*
I do not know how to validate a field with regexp. I find the documentation not explicit enough on that topic.
From the documentation.
Pattern
The pattern rule property indicates a regular expression that the
value must match to pass validation.
Use
{required: true, pattern:/\D*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4})\D*/, message: 'Please input phone', trigger: 'blur' }
Updated fiddle.

A2LiX Translations validation not working when all fields are submited as empty

When I don't provide any of the translatable properties through my submit form, then I get no validation checking, even when I have implemented:
/**
* #Assert\Valid
*/
protected $translations;
In config.yml I have:
default_locale: cs
required_locales: [cs]
All topics about this problem were giving importance on the #Assert/Valid on $translations property, which I have implemented (I have even tried validation.yml configuration).
Now I realise, that I forgot to add, that I am displaying and submiting the form through Easy Admin bundle. I am not building the form myself. Just configuring Easy Admin settings for my entity. Maybe there's some glitch.
Please refer the following answer link related to same question:
Collection array name fields validation:
A2Lix form validation for translations field
try adding required option to your easy admin type settings
- { property: 'translations', type: 'a2lix_translations', type_options: { required: true} }

Where should we write validation code for a form in cfwheels?

I have just started learning cfwheels. I was working on the sample "Social Networking Site" example present in the site(http://cfwheels.org/screencasts/series/1).
I have a doubt. We have register.cfm and login.cfm two views present. Both the veiws are using the user object
created from Person.cfc(modal).
All the validations that are required in the registration form , we have written inside Person.cfc init() method. Now on the login.cfm
we have two fields named Email and password and I want to validate the email to be in correct format in server side before checking
for valid Email/Password combination.
Now where should I write this validation code for login.cfm?
The server side validation should be done on the action inside the Controller.
For example if you are submitting the form to doLogin action of the Authentication controller/component, the validation code should go inside the doLogin() function of the same controller.

Laravel 4 regex email validation

I am trying to add validation, inside my User model to validation emails using regex.
However, it's spits a dummy out at the first apostrophe.
'email' => 'required|regex:/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+#[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/',
Have you tried the 'email' validation rule?
'email' => 'required|email|unique:users,email'
http://laravel.com/docs/4.2/validation#rule-email
As the answer to this question on SO states, there is no simple regular expression to validate an email-address. Using your RegEx could maybe catch valid addresses (although that's just speculation of mine). Using the email-validation-rule would be my first choice.
But you are right, this is just the server side in the first place, if you ignore redirecting users back with input and error messages..
On the client-side, you would have some options. The first one would be to simply rely on the build in browser-validation, by declaring the corresponding input-field as an email-address which you should do anyway:
{{ Form::email($name, $value = null, $attributes = array()) }}
Another, more advanced way would be to create some kind of helper to check the typed input via Ajax using the same validation rule and returning the error messages or sth. similar. This could be an additional route to your Model-Resource for example. This way, you would be stable and consistent.