Regex for only positive decimals from 0 to 1 upto 2 decimal digits only that works without sign in JavaScript?

I basically want a regex for alpha in RGBA which is always a positive number between 0 & 1. However, I want it to only be upto 2 digits 0.53 & not more than that like 0.536.

Allowed

Anything between 0 to 1 but only upto 2 decimal places

0
0.0
0.00
0.1
0.12
0.34
1
1.0
1.00

Not Allowed

Anything outside of 0 to 1 & if its between 0 to 1 then it should be less than or equal to 2 decimal places only & even signs not allowed

0.123
90
3
-1
+1

I noticed other similar questions but they allow signs or they allow more than 2 decimal places.

Currently, I have a regex like /^(0+\.?|0*\.\d+|0*1(\.0*)?)$/ which allows for more than 2 decimal places. How do I solve it?

43 thoughts on “Regex for only positive decimals from 0 to 1 upto 2 decimal digits only that works without sign in JavaScript?”

  1. I believe what you posted was actually very reasonable. However,
    consider this, suppose you added a little information? I am not suggesting your information isn’t good, but suppose you added a title
    that makes people desire more? I mean Regex for only positive decimals from 0 to
    1 upto 2 decimal digits only that works without sign in JavaScript?
    – JavaScript Help is a little vanilla. You could glance at Yahoo’s home page
    and see how they create news titles to grab people to open the links.

    You might add a video or a related pic or two to grab people interested about everything’ve got to say.
    In my opinion, it could bring your posts a little livelier. http://cleckleyfloors.com/

    Reply

Leave a Comment