Dynamic Max Length Value in Codeigniter - codeigniter

can i set max_length validation dynamicly? For example max_length['.$this->store->select($id)->stock.'] <-- It's not working

Just make sure, $this->store->select($id)->stock returning valid numbers:
$this->form_validation
->set_rules(
'your_field',
'Label',
'max_length['.$this->store->select($id)->stock.']'
// You can also trim it before checking length like below
//'trim|max_length['.$this->store->select($id)->stock.']'
);

Related

What is the equivalent function in AmiBroker AFL for "ta.change" in TradingView Pine-Script?

I need to know the function from AmiBroker AFL which serves the same purpose as "ta.change" from TradingView Pine Script. "ta.change" Compares the current source value to its value length bars ago and returns the difference between the values when they are numerical. When a 'bool' source is used, returns true when the current source is different from the previous source.
Regards.
In AFL you can use Ref function to calculate change:
length = 5;
change = source - Ref( source, -length );

Laravel rule to checking length is not equal to N

We have defined some rules in laravel but we need rule in which length of string should not be 5.
code is given below.
$rules = array(
'id' => 'required|numeric|digits_between:7,8'
);
current rule is length would be in between 7 and 8 but i need to modify it to length should be anything but not equal to 5. Please help to resolve.
Never forget regexs :)
Here is an example that prevents length =5, not_regex is used cause d{} cant be negated so i consider this the optimal and shortest solution
'id' =>'required|not_regex:/\b\d{5}\b/',
hope it helps

Laravel Validation should fail yet getting SQL exception error of "out of range"

Laravel 5.5
10.1.32-MariaDB
I am QA'ing some entries where I have the following rule:
'required|numeric|min:0|max:9999999999999999.99999999'
That column has a float type of double(16,8), now if I insert the number above + 1 which should fail validation and redirect with errors, I get a MySQL error: Numeric value out of range: 1264 Out of range value for column
Am I missing something in my validation rule?
Max validator works only with integer values:
Docs for Max validation rule:
Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.
Size rule description:
... For numeric data, value corresponds to a given integer value. ...
In your case validator simply ignores the max validation rule.
Perhaps you would like to create custom validation rule.

Flutter: Setting a range of accepted values and multiple conditions to a TextFormField validator

I'm using many TextFormFields as number input fields and want to ensure the user can only enter a value from an acceptable range of numbers. For example an age field should only accept numbers between 18 and 100, and only integers rather than decimals.
Which brings me to the second half of my question: how can I use the validator property to specify two or more conditions to one field? Say for the age field; input must be inside designated range, input must be a whole number, input must not be empty. I am able to create a working validator with, say, one of these conditions, but how do I ask it to validate multiple things in the same TextFormField?
Please let me know if there is any other information I can provide to assist you in answering, I didn't feel a code example would have been useful because the issue is non-specific.
EDIT: have (for the most part) figured out the multiple conditions issue, still in the dark about creating a number range of accepted values. A specific example solution for my age field would be a big help.
Example code:
...
String validateAge(String value){
String pattern = r'(^[0-9]*$)';
RegExp regExp = new RegExp(pattern);
if (value.length == 0){
return "Age is required.";
} else if (!regExp.hasMatch(value)){
return "Age cannot contain characters other than numbers.";
}
}
...
new TextFormField(
decoration: InputDecoration(
hintText: "Age"
),
validator: validateAge,
autoValidate: true,
),
If you parse the value to a number, then you don't need to use regexp
var numValue = int.tryParse(value);
if(numValue >= 5 && numValue < 100) {
return true;
}
You can for example check if value.length > 0 and numValue > 0 to know that the string was not a valid number for
"Age cannot contain characters other than numbers."

validation on discount between 0 and 0.999 in laravel 5

I need to apply validation on discount filed accept value between 0 and 0.999
like: 0.25, 0.0125, 0.09
I tried
'discount' => 'required|max:0.999'
but got: The discount may not be greater than 0.999 characters.
The max rule looks at the type of the variable being sent to it and applies the appropriate logic. For numbers, it works like you intend - it compares the numerical value.
But for strings, it means that the string may not be longer than the max. In your case, Laravel thinks you're sending a string and tries to validate it as such. Your variables probably aren't 0.25, 0.5, etc., but rather "0.25", "0.5", etc. If you convert them to floats, it should work fine.
If, for instance, your values come directly from forms, they're most likely in string form, not float.
Size is what you need here
The field under validation must have a size matching the given value.
For string data, value corresponds to the number of characters. For
numeric data, value corresponds to a given integer value. For files,
size corresponds to the file size in kilobytes.
'discount' => 'required|size:0.999'
'discount' => 'required|numeric|max:0.999'

Resources