user1387287
user1387287

Reputation: 43

Regex on positive numeric with dollar sign

Could someone post some tip on what's the pattern for Regex for postive numeric number with decimal and dollar sign.

Valid:

1.50
25
25.50
$1.50
$25
$25.50

Upvotes: 0

Views: 1040

Answers (2)

detale
detale

Reputation: 12912

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

This one also excludes $05.00

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

This one allows $ .3

Update: to filter 0 and $0

(\$\s*)?(([1-9]\d*)(\.\d+)?|0?\.\d*[1-9]\d*)

Upvotes: 0

Sufian Latif
Sufian Latif

Reputation: 13356

This one should do it:

\$?[0-9]+(\.[0-9]+)?

Upvotes: 4

Related Questions