You must Sign In to post a response.
  • Category: [Competition Entries]

    Need regular expression

    I need a regular expression for entering negative & positive numbers with two decimal places. I have a regular expression as :
    /^[-+]?\d+(\.\d{1,2})?$/

    But , it wont take .75.take only 0.75.

    Can any1 help me?
  • #687310
    Hi,

    I believe that is the right regular expression, because before the decimal point you should have zero or some other value.


    Regards,
    Asheej T K

  • #687332
    Try with the following regular expression it may help you.
    where we accept number from 0-9 and after decimal we accept 2 digits


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

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #687333
    try this one

    ^[-+]?([0-9]*\.)?[0-9]{2}

    This matched

    0.75
    0.75
    -0.75
    +0.75
    .75

    .75
    .75

    0.00

    Thanks & Regards,
    Danasegarane Arunachalam

    http://www.techreceipe.tk/

  • #687384
    This wont match for the number 1212

  • #687428
    Try like this regular expression


    var regex = /[0-9-][.][0-9]{2}$/;

    Regards
    N.Ravindran
    Your Hard work never fails


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.