SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex test for any non digit, but . is ok

    How can I test a variable for any non digit, but not match a decimal point. Right now I have:
    Code JavaScript:
    if(/\D/.test($variable)){ 
                return false;
    }
    else {
                return true;
    }

    how can I make the regex not match decimal points?
    Thanks for any help.

  2. #2
    SitePoint Zealot blackman890's Avatar
    Join Date
    Feb 2005
    Location
    Iceland
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this: [^.0-9]
    Jonatan Nilsson
    Iceland
    C# Programmer - XML & DirectX (y = hx + c)

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that's what I needed. Thanks.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way to change [^.0-9] to match more than 1 decimal point. so one decimal point would be ignored. but it would match a second?

  5. #5
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sd3923 View Post
    is there a way to change [^.0-9] to match more than 1 decimal point. so one decimal point would be ignored. but it would match a second?
    This picks up more than one point even if they are not adjacent:
    Code:
    /[^0-9\.]|(\.[^\.]*\.)/
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •