numeric

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • earl

    numeric

    arrDate = date.split('/');

    How can I check if each array element contain only numeric values ?


  • Lasse Reichstein Nielsen

    #2
    Re: numeric

    "earl" <b@email.com> writes:
    [color=blue]
    > arrDate = date.split('/');
    >
    > How can I check if each array element contain only numeric values ?[/color]

    I assume you want them to be non-empty too (the empty string contains
    only digits, all zero of them).

    I would test before splitting, so you can get away with only one test.

    If you know there must be exactly three parts, then try this:

    if (!(/^\d+\/\d+\/\d+$/).test(date)) {
    // error.
    }

    If you accept any number of parts, then
    if (!(/^\d+(\/\d+)*$/).test(date)) {
    // error.
    }

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...