checking to make sure that an input is a number 
Author Message
 checking to make sure that an input is a number

I need to know how to check if an input is a number.
Help.
Not just an integer but a positive number


Sun, 15 May 2005 02:50:49 GMT  
 checking to make sure that an input is a number
Try regular expressions.
This one:
    ^[+]?\d+(\.\d+)?$
was taken from the site:
http://regexlib.com/REDetails.aspx?regexp_id=117
You can go to the site and test it to see if it suits your needs.



Quote:
> I need to know how to check if an input is a number.
> Help.
> Not just an integer but a positive number



Sun, 15 May 2005 02:53:52 GMT  
 checking to make sure that an input is a number
Oops,
Sorry, the expression I gave you
^[+]?\d+(\.\d+)?$
matches positive number while the one on the site
^[-+]?\d+(\.\d+)?$
matches positive and negative numbers.


Sun, 15 May 2005 03:01:40 GMT  
 checking to make sure that an input is a number
That works except if I have .125 this returns false...

Quote:
> Try regular expressions.
> This one:
>     ^[+]?\d+(\.\d+)?$
> was taken from the site:
> http://regexlib.com/REDetails.aspx?regexp_id=117
> You can go to the site and test it to see if it suits your needs.



> > I need to know how to check if an input is a number.
> > Help.
> > Not just an integer but a positive number



Sun, 15 May 2005 03:11:24 GMT  
 checking to make sure that an input is a number
Try this:
^[+]?(\d+)?(\.)?(\d+)?$



Quote:
> That works except if I have .125 this returns false...


> > Try regular expressions.
> > This one:
> >     ^[+]?\d+(\.\d+)?$
> > was taken from the site:
> > http://regexlib.com/REDetails.aspx?regexp_id=117
> > You can go to the site and test it to see if it suits your needs.



> > > I need to know how to check if an input is a number.
> > > Help.
> > > Not just an integer but a positive number



Sun, 15 May 2005 03:40:30 GMT  
 checking to make sure that an input is a number
OK Now I am really going to show how little i know about jscript
How do I use this.
I have the value  f.size.value


Quote:
> Try this:
> ^[+]?(\d+)?(\.)?(\d+)?$



> > That works except if I have .125 this returns false...


> > > Try regular expressions.
> > > This one:
> > >     ^[+]?\d+(\.\d+)?$
> > > was taken from the site:
> > > http://regexlib.com/REDetails.aspx?regexp_id=117
> > > You can go to the site and test it to see if it suits your needs.



> > > > I need to know how to check if an input is a number.
> > > > Help.
> > > > Not just an integer but a positive number



Sun, 15 May 2005 04:39:46 GMT  
 checking to make sure that an input is a number
Untested.
Look into RegExp for more information.
Sorry, I mostly use regular expressions testing in ASP and the expression I
gave you earlier was in ASP.

function only_digit(src)
{
  if (src.value.match(^[\d+]?[\.]?[\d+]?$))
  {
 alert("Numeric only");
 return false;
  }

return true;

Quote:
}



Quote:
> OK Now I am really going to show how little i know about jscript
> How do I use this.
> I have the value  f.size.value



> > Try this:
> > ^[+]?(\d+)?(\.)?(\d+)?$



> > > That works except if I have .125 this returns false...


> > > > Try regular expressions.
> > > > This one:
> > > >     ^[+]?\d+(\.\d+)?$
> > > > was taken from the site:
> > > > http://regexlib.com/REDetails.aspx?regexp_id=117
> > > > You can go to the site and test it to see if it suits your needs.



> > > > > I need to know how to check if an input is a number.
> > > > > Help.
> > > > > Not just an integer but a positive number



Sun, 15 May 2005 05:47:08 GMT  
 checking to make sure that an input is a number


Tue, 26 Nov 2002 13:50:49 :-

Quote:
>I need to know how to check if an input is a number.
>Help.
>Not just an integer but a positive number

You probably do not need to know that.  For example, "positive number"
includes 3.14159E0 and 5E+300 - do you need to accept those?

If what you are doing is in essence inputting a count, then you can call
and test for a number of 1 to N decimal digits, using a RegExp such as
/\d{1,8}/.

For the case of non-integer, you should require at least one digit on
each side of the decimal point; and you should perhaps require the
decimal point.  Allowing numbers to have a decimal point at one end
becomes error-prone.
If the input is a currency, you should probably not allow just a single
digit after a decimal point; that is liable to be an error.

Beware of allowing an empty string, unless specified permissible.

--

  <URL:http://www.jibbering.com/faq/> FAQ for comp.lang.javascript by Jim Ley.
  <URL:http://www.merlyn.demon.co.uk/js-index.htm>   JS maths, dates, sources.
  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.



Sun, 15 May 2005 22:06:37 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Check to make sure an input is an integer

2. check input field, only numbers accepted

3. Check if input is number or text?

4. silly newbie question i am sure

5. Validating form field to make sure it's a number

6. I am sure this shoudl go to an MS Access list but not sure where I can find one...

7. help Making a web page navigate to an address created with an input string

8. Checking to make sure X number of digits entered.

9. Form input validation international phone number

10. Checking Input Box Types

11. how to check input on form submission?

12. VBScript to check CLSIDs/ProgIDs from list in input file

 

 
Powered by phpBB® Forum Software