SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FIXED: decimal number regular expression

    i've tried 4 different patterns but it still seems to be returning false for 1.00. anyone have any ideas?
    Code:
    function CheckNumber(x){
    	//var anum=/(^\d+$)|(^\d+\.\d+$)/;
            ///[-+]?[0-9]*\.?[0-9]+/;
    	///^-{0,1}\d*\.{0,1}\d+$/;
    
    	var anum=/^\-?\(?([0-9]{0,3}(\,?[0-9]{3})*(\.?[0-9]*))\)?$/;	
    	var testresult;
    
    	if (anum.test(x))
    		testresult=true;
    	else{
    		testresult=false;
    	}
    	return (testresult);
    }
    NEVER MIND.... syntax error

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since I already loaded up rxtoolkit, I might as well throw my result in for comparison.

    Code:
    ^([-+]?)([0-9]+)(\.([0-9]+))?$
    Seperating everything nicely into groups 1,2 & 4.

  3. #3
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm. thanks for that, but it's working now. error in the way i was sending in the value. figures, always something simple in a place i'm not looking...


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
  •