SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Bruce Lee's Avatar
    Join Date
    Jan 2005
    Location
    Singapore
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whats does /^\d*$/ stand for?

    in the existing code i see the piece of code.

    ---------------------
    re = /^\d*$/
    var qScore = document.myform["esmark" + qID].value
    if (!re.test(qScore) )
    {
    alert("Please input a numeric value.")
    return;
    }
    -------------------

    whats does
    1. /^\d*$/ indicate?
    2. re.test is a javascript function?
    Happy Coding!!!
    Bruce Lee.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2006
    Location
    Nantwich, Cheshire
    Posts
    468
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    The "/^\d*$/" part is a regular expression, a standard way of defining a pattern to match against. Basically you interpret it like this:

    First, remove the leading and trailing / characters as these are delimiters which appear at the start and end of all regular expressions. This leaves you with ^\d*$

    The ^ at the beginning is a code to signify that the regular expression must match from the start of the supplied string. The $ means the same for the end. So we're going to check that the string supplied (from the form) matches with nothing at either end, i.e. a match rather than a 'containing' search.

    The \d signifies a numeric digit, and the * means multiple digits.

    So basically, the check we're doing is to get the form value, and make sure that every character in the string is a numeric digit, with nothing at either end.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by droopsnoot
    The \d signifies a numeric digit, and the * means multiple digits.
    To be specific, the * means 'zero or more'. So the expression matches an empty string or a string comprising any number of decimal digits.
    Birnam wood is come to Dunsinane


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
  •