locked
Reg REGEX expressions for numeric(13,3) and string MM.YYYY RRS feed

  • Question

  • Hi All,

    Kindly help in writing regex expression for the ffollwoing

    1) MM.YYYY

    MM-Month- digits

    YYYY-digits and year

    eg:- 12.4567- Allowed

    13.2012 -not allowed

    2) numeric(13,3)

    - negative also allowed and no commas allowed

    eg:-14582,123.466 allowed

    123.1234234 not allowed


    Muqeem

    Saturday, September 29, 2012 11:51 AM

Answers

  • Hi All,

    Kindly help in writing regex expression for the ffollwoing

    1) MM.YYYY

    MM-Month- digits

    YYYY-digits and year

    You can use:

    \b(?:0[1-9]|1[0-2])\.\d{4}\b

    If you want to make the leading "0" optional rather than required, as I did, then merely change "0" to "0?" in the regex above.

    But for:

    2) numeric(13,3)

    - negative also allowed and no commas allowed

    eg:-14582,123.466 allowed

    123.1234234 not allowed

    I don't understand what format you are describing. Please clarify.

    What you show for "allowed" is not a normally formatted number, at least in the US.  If it were using comma separators, you are missing one  (e.g: 14,582,123.466 would be an appropriately formatted number).  In other words, a US formatted number would have zero or two commas for a number of that range, but not one.

    Edit:  You also wrote "no commas allowed" yet in your example:  14582,123.466 allowed; there exists a comma. ?????


    Ron




    Saturday, September 29, 2012 2:54 PM