0

I am trying to support the following formats:

11.11

01.67

30.03

11.45.23

But the Regex i used "/^[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$/" supports only first 3 formats.

I need to match numbers with 1 or more decimal points like 11.12.36

Please help me out!

  • Is a leading or trailing "." acceptable? `.12` or `34.` for example. – Chris Farmer Apr 12 '12 at 05:15
  • So it looks like you actually need to match more than what you say. If you needed to match just decimals and numbers, you could just do this `/^[\d\.]*/` What are your actual criteria? – kmiyashiro Apr 12 '12 at 05:17
  • Regex should accept more than 1 decimal point as like "11.12.36" –  Apr 12 '12 at 05:21
  • But is the maximum constraint 3 decimal points? If it is `/^[+-]?\d+(\.\d+(\.\d+)?)?$/` will work. If it's more that 3 you're going to have to use a collection of matches. – Jason Larke Apr 12 '12 at 05:36
  • Please add the constraints. Can we have leading or trailing decimal places. How many digits before a decimal place etc. Minimum and max no. of "." allowed. – NoviceProgrammer Apr 12 '12 at 06:23
  • Should it still also match numbers like `-1.23E+45` or are you really looking to match IP addresses? – Mr Lister Apr 12 '12 at 06:25
  • http://stackoverflow.com/questions/1014284/regex-to-match-2-digits-optional-decimal-two-digits – Praveen Kumar Apr 12 '12 at 06:36

2 Answers2

1

Try this.

sPattern = @"^\d{2}\.\d{2}(\.\d{2})*$";

it will include all numbers

11.11

23.45.57

12.54.78.78
aleroot
  • 71,077
  • 30
  • 176
  • 213
Akanksha Gaur
  • 2,636
  • 3
  • 26
  • 50
0

If you want to allow any number of digits between your decimal points and any number of decimal points including a possible starting decimal point you could try something like:

\.?\d+(?:\.\d+)*

This will allow things like .123 123.123 123.123.123.123 etc

msam
  • 4,259
  • 3
  • 19
  • 32