Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating number regex between 0 and 1

Tags:

regex

I'm trying to validate input for floating number which max value is 1.0 and min value is 0.

Min : 0
Max : 1

Possible values ;

0.1
0.99
0.365

how can i succeed it with regex?

like image 398
Fatih Donmez Avatar asked Jan 22 '13 15:01

Fatih Donmez


People also ask

Can a regular expression match a floating point number?

As an example, we will try to build a regular expression that can match any floating point number. Our regex should also match integers and floating point numbers where the integer part is not given. We will not try to match numbers with an exponent, such as 1.5e8 (150 million in scientific notation).

What is the range of regex numbers?

The Regex number range include matching 0 to 9, 1 to 9, 0 to 10, 1 to 10, 1 to 12, 1 to 16 and 1-31, 1-32, 0-99, 0-100, 1-100,1-127, 0-255, 0-999, 1-999, 1-1000 and 1-9999.

How do I use a regex to match characters from 0 to 255?

Since regular expressions work with text, a regular expression engine treats 0 as a single character, and 255 as three characters. To match all characters from 0 to 255, we'll need a regex that matches between one and three characters. The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99.

What does spelling out the regex in words mean?

Spelling out the regex in words makes it obvious: everything in this regular expression is optional. This regular expression considers a sign by itself or a dot by itself as a valid floating point number. In fact, it even considers an empty string as a valid floating point number.


1 Answers

As javascript regex literal:

 /^(0(\.\d+)?|1(\.0+)?)$/
like image 131
MikeM Avatar answered Oct 12 '22 22:10

MikeM