regex for age with 2 decimal points - javascript

What is regex for age with 2 decimal points value with max value 99.11
Valid examples:
1
12.01
16.06
20.11
Invalid examples:
.0
1.12 (decimal value should be <12)
1.13 (decimal value should be <12)
12.111
100.00 (2 digit before decimal point, max 99.11)
I have tried ^[0-9]\d{0,1}(\.\d[0-1]\d{0,1})*(,\d+)?$ regex but it is not following all criteria.
can anyone help me?

You can try with this pattern:
/^\d{1,2}(\.(0[0-9]|1[01]))?$/
var pattern = /^\d{1,2}(\.(0[0-9]|1[01]))?$/;
console.log(pattern.test('1'));
console.log(pattern.test('12.01'));
console.log(pattern.test('16.06'));
console.log(pattern.test('20.11'));
console.log(pattern.test('.0'));
console.log(pattern.test('1.12'));
console.log(pattern.test('1.13'));
console.log(pattern.test('12.111'));
console.log(pattern.test('100.00'));

Try this.
/^\d\d?(\.(0\d|1[01]))?$/
Description:
^\d\d? - from the start of the string, match 1 or 2 numbers
After that/those numbers, optionally match . plus 2 numbers
The two numbers must be 0 and any number, else 1 and 0 or 1
Anchor to the end of the string

You are missing the two different patterns of floating part, which must be handled with a |.
A character-optimal solution is ^\d{1,2}(\.[0]\d|\.1[01])?$.

Related

regular expression no more than one digit

how to make a regular expression into one number (only numbers) and that it does not exceed 10 from 0 to 10
/^[1-9][1]*$/.test(message)
It doesn't work that way for me.
To specify the amount of a specific character use {} instead of [], in this case, as it is only one digit, you do not need to specify a count as 1 is default:
/^[0-9]$/.test(message)
I assume you mean you want to match a single digit between 0 and 10. If not please comment to clarify.
Hope this helps.
Assuming you only want integers or whole numbers, then use:
/^(?:[0-9]|10)$/
If you want to allow for decimals, then use:
/^(?:[0-9](?:\.\d+)?|10(?:\.0+)?)$/
The second regex says to match:
^ from the start of the number
(?:
[0-9] 0 to 9
(?:\.\d+)? any optional decimal component
| OR
10 match integer 10
(?:\.0+)? optional zero decimal only
)
$ end of the number

How to create a Regular Expression with the following conditions

Numerical input should not exceed 8 digits ( counting numbers on both the side of the decimal). Example: 123456.78 or 0.12 or 1.23
Numerical values should be able to accept negative numbers. Example: -0.8 , or -1.23
Max of 2 decimal number allowed
Numerical value should not accept any alpahbets in the input box
I tried Creating the following regular expression but i am not able to figure it out quite efficiently
^-?[0-9]\d*(\.\d+)?[,8]$
Regular exp
To match the required number of digits and no more, lookahead at the beginning of the pattern for (?:\d\.?) 1 to 8 times, and then match \d*(?:\.\d{1,2})?$ to match a number which, if containing decimals, contains at maximum 2 decimal characters:
^-?(?=(?:\d\.?){1,8}$)\d*(?:\.\d{1,2})?$
https://regex101.com/r/rQMRVX/5
(unless you need to capture the decimal part, it can be a non-capturing group like above)
You can try this
^-?\d{1,8}.?\d{1,2}$
Link : https://regex101.com/r/x7yw5M/2

Regular expression for length limit 10 digit before decimal till 2 decimal place with Number only?

i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed
1
1111111111
111
1111111111.22
.2
1.2
1.22
Not allowed
4.
.
-1
abc
Null
Emptystring
""
1.222
-1.22
111111111111
tried but not working
^[0-9]*(\.[0-9]{0,2})?$
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to \d.
In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:
^(?!$)\d{0,10}(?:\.\d{1,2})?$
https://regex101.com/r/Ah8dNu/5
I have also prepared below RegEx.
Seems this will also work.
^[0-9]{1,10}((\.)[0-9]{0,2}){0,1}$

currency regex with decimal allowed with 0

With reference to my previous question currency regex
I want to add an condition, i want to allow decimal only if it starts with 0
example
0.25 should be allowed
1.25 not allowed
current regex is as following
/^(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?$/
which matches comma trailing etc.
This will match all the currency matches from before without decimals or decimals with 0.x*
/^((?:\d{1,3}(?:,\d{3})+|\d+)|(?:0\.\d+))$/
If you only want to match 0.xx instead of an arbitrary number of decimal places use
/^((?:\d{1,3}(?:,\d{3})+|\d+)|(?:0\.\d{2}))$/
This one changes \d+, one or more digits, to \d{2}, exactly 2 digits.

JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

Could any of you help me with a regular expression which will accept these:
For every thousand a comma will be accepted.
No less than 4 decimal points in number
I've been testing this pattern but fails in some scenarios:
^\d+(\,\d+{1.3} \.d{1.4})*$
Valid inputs:
1
11
111
1,111
1,111,111
1.1111
11.1111
111.1111
1,111.1111
Invalid inputs:
Any letter
1,1
1.1
1.11
1,11.11
1,111.1
The main criterions are:
(4 decimal points are obligatory).
(3 numbers per thousand must have a comma.)
Is this more complicated than
/^\d\d?\d?(,\d\d\d)*(\.\d\d\d\d)?$/
or if you prefer
/^\d{1,3}(,\d{3})*(\.\d{4})?$/

Categories

Resources