user3134939
user3134939

Reputation: 37

regex for comma separated value of multiple of 100 and upto 1000

Can any body help me out for one regular expression ,which validate comma separated values of multiple of 100 and upto 1000 only.

For example 100,200,1000 for example 100,1000,100

Regards, PK

Upvotes: 1

Views: 349

Answers (2)

revo
revo

Reputation: 48751

^(?:1000,?|[1-9]00,?)+$

Live demo

Upvotes: 1

Toto
Toto

Reputation: 91498

Have a try with this one:

^(?:10|[1-9])00(?:,\s*(?:10|[1-9])00)*$

Explanation:

The regular expression:

(?-imsx:^(?:10|[1-9])00(?:,\s*(?:10|[1-9])00)*$)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  (?:                      group, but do not capture:
----------------------------------------------------------------------
    10                       '10'
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    [1-9]                    any character of: '1' to '9'
----------------------------------------------------------------------
  )                        end of grouping
----------------------------------------------------------------------
  00                       '00'
----------------------------------------------------------------------
  (?:                      group, but do not capture (0 or more times
                           (matching the most amount possible)):
----------------------------------------------------------------------
    ,                        ','
----------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
----------------------------------------------------------------------
    (?:                      group, but do not capture:
----------------------------------------------------------------------
      10                       '10'
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      [1-9]                    any character of: '1' to '9'
----------------------------------------------------------------------
    )                        end of grouping
----------------------------------------------------------------------
    00                       '00'
----------------------------------------------------------------------
  )*                       end of grouping
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

Upvotes: 4

Related Questions