Jbisgood9999999 - 7 months ago 29

Javascript Question

I need a regular expression in javascript that will accept only positive numbers and decimals end with .5 or .0 .

`(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)`

This is what i have but i don't know how to change to reject 0 and 0.0, and reject those end with .1 .2 .3 .4 .6 .7 .8 .9

`Accept:`

0.5

1.0

1.5

2.0

2.5

3.0

1

2

3

4

But

`Reject:`

-1.0

-0.5

-0.0

-0.1

-0.7

0.0

0.1

0.9

0.4

1.3

Answer

How about the following regular expression: `^\d*\.\d{0,}(0|5)`

?

Here is the explanation:

```
^ //line start
\d* //any number (or none) occurrences of any number
\. //decimal dot
\d{0,} //0 or more digits
(0|5) //ends with 0 or 5
```