'Creating a RegExp expression that limits the maximum input number to 2*pi radians (360 degrees) (in a Flutter app)

I am building a Flutter app that has a textfield input, in which the user types an angle. There is a toggle that allows the user to change the unit between degrees and radians. The angle is related to compass directions, so I naturally want to allow a maximum input values of 360 degrees, or 2*pi radians. I have managed to build an expression that works for degrees, which looks like this:

r'^\b([0-2]?[0-9]{1,2}|3[0-5][0-9]|360)\b'

This expression allows whole numbers between 0 degrees and 360 degrees. If there's a way to modify this to allow decimals as well, that would be fantastic, although it isn't absolutely necessary.

Creating an expression that works when a user has toggled the input units to be radians is where I am struggling. Essentially, it needs to allow users to type in a number with up to two decimal places (or none at all) with a maximum of 6.28 radians. Below you can see what I have managed to put together so far:

r'^\b(6|([1-6])\.?|0\.[1-9]\d*)$\b'

As you will probably see straight away, this just doesn't work. I am aiming to allow users to input a value between 0 radians and 6.28 radians. I also want them to be able to type in a decimal number with no digit in front, such as .3 radians and to be able to type in a number with a decimal point but nothing after, such as 3. radians.

Can someone help me understand where I am going wrong with this? What should my RegExp expression look like, to cater for this? Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source