validation on exact length of numeric field in laravel 5 - laravel

I have numeric field i want to validate on exact fill 4 digits.
like: 1234, 4567,1245
but these invalid inputs:
like: 123, 346, 45m6, 34567
what I am trying:
'last4digits' => 'numeric|between:4,4',

You are looking for the digits rule. From the docs:
The field under validation must be numeric and must have an exact length of value.
'last4digits' => 'digits:4'

in general case ,say, for a string with arbitrary characters:
'last_not_only_4_digits' => 'size:4'

Related

Validate a numeric string has a fixed amount of chars

I'm trying to use a validator to validate that the field cedula is a numeric string but also have 10 chars.
For example:
132456 Would not be validated because it is a numeric string but only has 6 chars
1315987423 Would be validated because it is a numeric string and has 10 chars
131598742B Would not be validated because it isn't a numeric string because of the B in the end
Im trying to validate it like this in the validator
'cedula' => ['required', 'numeric', 'size:10'],
But it only allows me to input the value of 10 and not a numeric string of 10 chars like 1315987423 that is what I desire to validate
How can I make the validator do what I need to do in this case?
Cedula is a string, not an int
Edit: Already realized that I should use digits to validate what I want to do.
I have found this post about your question.
I supose that this is the info which you are loocking for.
'cedula' => 'numeric|required|unique:personas|min:100000|max:99999999',
This should work
'cedula' => ['required', 'digits:10'],
The integer under validation must have an exact length of value.
Source: https://laravel.com/docs/9.x/validation#rule-digits

NiFi EL How do I get a substring "up to" certain length?

I have this expression to print the first N chars of the flow file content. The problem is when the content length is less than N. What's a good way to say "up to first N chars". That is I will not get an index out of bounds error when the size is less than N.
${incoming_content.0:substring(0,100)}
Here my N=100
Thank you.
If the content of your flow files are not too big, you can use ExtractText to convert contents of flowfile as attribute and then use UpdateAttribute processor to run following logic
${incoming.0:length():le(100):ifElse(${incoming.0},${incoming.0:substring(0,100)})}
which is essentially checks if length of flowfile contents (in attribute) is less than equals to 100, if true, return entire string as is, else return substring up to 100 characters
I was also getting the index out of bound error, and hence created the below expression:
${firstName:length():gt(0):ifElse(${firstName:substring(0,5)},'')}
:length() => fetching the length of string ,
:gt(0) => return boolean true if length is greater than 0 ,
:ifElse => If true, then get first 5 characters, Else return empty string
I have tested the above expression having firstName attribute value as null, "" and "very long name".
Here is the link to Nifi Expression guide

In angular 2, how to display a number as two decimal rounded currency?

Examples:
1.99 --> $1.99
1.9 --> $1.90
1 --> $1.00
1.005 --> $1.01
1.004 --> $1.00
I am using {{num | currency:'USD':true}} but it does not show trailing 0s.
Use this code. Here is a working example http://plnkr.co/edit/xnN1HnJtTel6WA24GttR?p=preview
{{num | currency:'USD':true:'1.2-2'}}
Explanation :
number_expression | number[:digitInfo]
Finally we get a decimal number as text. Find the description.
number_expression: An angular expression that will give output a number.
number : A pipe keyword that is used with pipe operator.
digitInfo : It defines number format.
Now we will understand how to use digitInfo. The syntax for digitInfo is as follows.
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
Find the description.
minIntegerDigits : Minimum number of integer digits. Default is 1. (in our case 1)
minFractionDigits : Minimum number of fraction digits. Default is 0. (in our case 2)
maxFractionDigits : Maximum number of fraction digits. Default is 3. (in our case 2)
well you got the correct answer but still i think i can elaborate more this answer so posting it as answer:
First of all there are number of pipes available of the angular2 to use in our project some of them are listed below
CurrencyPipe , DatePipe, UpperCasePipe, LowerCasePipe, and PercentPipe and many more.
Here as your question you have problem related to currency pipe. so i want to explain bit more as other answers.
CurrencyPipe :
A pipe may accept any number of optional parameters to fine-tune its output. We add parameters to a pipe by following the pipe name with a colon ( : ) and then the parameter value (e.g., currency:'EUR'). If our pipe accepts multiple parameters, we separate the values with colons (e.g. slice:1:5).
{{number | currency:'your_type':true:'1.2-2'}}
here...first parameter is currency type which is either EUR,USD or anything, Second parameter is true/false for the symbolDisplay which is false byDefault. then Third one is range limit basically a range limit . You can set a min and max length after the decimal point and a fixed number (or leave it blank for default) for the places before the decimal point.
I have found some good tutorials for the pipes in the angular2 which i am posting here..
http://voidcanvas.com/angular-2-pipes-filters/
https://angular.io/docs/ts/latest/guide/pipes.html
Hope it Helps and clarify more about pipes !!
#Pardeep !!
You are using the correct pipe. You just need to add the digit info to the output.
{{num | currency:'USD':true}} should be...
{{num | currency:'USD':true:'1.2-2'}}
For reference: 'USD' represents the type of currency, true represents whether to show the currency symbol ($), and '1.2-2' represents the digit info.
The digit info is {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.
minIntegerDigits is the minimum number of integer digits to use and defaults to 1.
minFractionDigits is the minimum number of digits after fraction and defaults to 0.
maxFractionDigits is the maximum number of digits after fraction and defaults to 3.
Source for the digit info can be found here: https://angular.io/docs/ts/latest/api/common/index/DecimalPipe-pipe.html
If, like me, you're trying to do this in the typescript/javascript rather than HTML, you can also use toLocaleString
So to convert a number to a currency string:
ppCurrency(number) {
return number.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
Following will convert with 2 decimal digits
{{num | currency : '$' : 2}}
angular 2
{{num | currency:'USD':true:'1.2-2'}}
<input type="number" [(ngModel)]="myModel" (keyup)="onBlurMethod()">
<br>
<br> The formatted currency is :
<br> {{myModel | currency:'USD':true:'1.2-2' }}
Here is the working example.
http://plnkr.co/edit/pSK8p7u3oo4WsAB9aFBS?p=preview
If any body gets a warning and wanted to resolve it, please find below the fix I used.
Following is the warning Angular displays in browser console:
Warning: the currency pipe has been changed in Angular v5. The
symbolDisplay option (third parameter) is now a string instead of a
boolean. The accepted values are "code", "symbol" or "symbol-narrow".
The format that causes the warning: currency: "USD":true:"1.2-2"
Fix: currency: "USD":'symbol':"1.2-2"
Reference: https://angular.io/api/common/CurrencyPipe

Regex for validating constant field with numbers

I am new to ruby. I am trying for a regex pattern matching for my input. My requirement is that my input should strictly adhere to the following format
CHECK ID#<number>
(Eg. my input should be CHECK ID#3213)
How do i frame the pattern for this?
If you want to extract the ID number use this
"CHECK ID#123".scan(/CHECK ID#(\d+)/).last.first.to_i # => 123
Because you just need one result there is not need to use .scan or .match
"CHECK ID#123"[/CHECK ID#(\d+)/, 1].to_i
How about this:
match = "CHECK ID#1221".match /^CHECK ID#(\d+)$/
puts match[1] if match
=> 1221

Django alpha numeric validation in form fields

I want to perform a field validation,but the conditions are
1)The field should have 10 character.
2)off these 1st 5 character should be alphabets and next 5 character should be numeric digits
I performed validation for maximum length check,but rest of the thing how to perform.Is that can be done on a single "if" condition.
I am searching for the logic in google for performing that,but not got any idea.Can any one help me to perform the same.
forms.py for length check
def clean_bookref(self):
cd=self.cleaned_data
bookref=cd.get('bookref')
if len(bookref)<10 and re.match(r'[A-z0-9]+', bookref):
raise forms.ValidationError("Should be 10 digits")
return bookref
I am using this code to do but it is not working.
Thanks
Perhaps you could use something like his:
def clean_bookref(self):
cd=self.cleaned_data
bookref=cd.get('bookref')
if not re.match(r'^[A-Za-z]{5}[0-9]{5}$',bookref) :
raise forms.ValidationError("Should be of the form abcde12345")
return bookref

Resources