I am just curious if this regex expression will be able to be shorten. it should allow ten digits.
/^(?!0 (?:\.0 )?$)(\d{1,2}\.\d{1,10}|\d{1,2}|(100)|(100\\.00)|(100\\.0000000000)|(100\\.000000000)|(100\\.00000000)|(100\\.0000000)|(100\\.000000)|(100\\.00000)|(100\\.0000)|(100\\.0000)|(100\\.000)|(100\\.0))$/
CodePudding user response:
You need to use
/^(?![0.] $)(?:\d{1,2}(?:\.\d{1,10})?|100(?:\.0{1,10})?)$/
See the regex demo.
Details:
^
- start of string(?![0.] $)
- no only0
and/or.
chars till end of string are allowed(?:
- either of\d{1,2}(?:\.\d{1,10})?
- one or two digits and then an optional occurrence of a.
and one to ten digits
|
- or100(?:\.0{1,10})?
-100
and then an optional occurrence of a.
and one to ten0
chars
)
- end of the group$
- end of string.