Whats wrong with this regular expression?

Discussion in 'ASP .Net' started by COHENMARVIN, Aug 19, 2005.

  1. COHENMARVIN

    COHENMARVIN Guest

    I am trying to use an regularexpression validator to match floating
    numbers.
    My expression doesn't work.
    Here it is:
    ValExpression = "(0|[1-9][0-9]*|[1-9][0-9]*\.[0-9]*|0\.[0-9]*)"
    The \. is supposed to match the decimal point, but entering any
    decimal point in a number doesn't work.
    Any help is appreciated.
    -- Marvin
    COHENMARVIN, Aug 19, 2005
    #1
    1. Advertising

  2. COHENMARVIN

    Peter Blum Guest

    I have two thoughts.

    1. The CompareValidator can validate decimal numbers by setting its Operator
    property to DataTypeCheck and Type=Decimal.

    2. If you are assigning ValExpression programmatically using C#, the \
    character is a special symbol. Always use two \ characters like this:
    ValExpression = "(0|[1-9][0-9]*|[1-9][0-9]*\\.[0-9]*|0\\.[0-9]*)"

    or use the @ symbol before the string to override the special characters:

    ValExpression = @"(0|[1-9][0-9]*|[1-9][0-9]*\.[0-9]*|0\.[0-9]*)"

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "COHENMARVIN" <> wrote in message
    news:...
    >I am trying to use an regularexpression validator to match floating
    > numbers.
    > My expression doesn't work.
    > Here it is:
    > ValExpression = "(0|[1-9][0-9]*|[1-9][0-9]*\.[0-9]*|0\.[0-9]*)"
    > The \. is supposed to match the decimal point, but entering any
    > decimal point in a number doesn't work.
    > Any help is appreciated.
    > -- Marvin
    >
    Peter Blum, Aug 19, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,287
  2. Edward
    Replies:
    0
    Views:
    827
    Edward
    Dec 4, 2003
  3. Gert Cuykens

    whats wrong with my reg expression ?

    Gert Cuykens, Jan 15, 2007, in forum: Python
    Replies:
    1
    Views:
    324
    James Stroud
    Jan 15, 2007
  4. equinox
    Replies:
    3
    Views:
    84
    equinox
    Dec 18, 2008
  5. jh3an
    Replies:
    5
    Views:
    145
    Ben Bullock
    Mar 16, 2008
Loading...

Share This Page