SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    js regex help plz

    guys,

    in php i do this regex $pattern = "/[0-9\s]\$/"; to ensure that only numbers are entered with spaces, does anyone know the javascript equivalent pz?

    thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    What problem are you having with that. AFAIK it should work the same. i.e. capture a number or whitespace character appearing before a dollar sign.

  3. #3
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,272
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    var pattern = /^\d+ ?$/;

    Though that says the pattern must start with a number.

    With regexes it's better to try to really know specifically what you're matching.

    *edit I misread the $ in the first post. Mittineague caught it.

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    :d'oh: I may have seen the escaped literal $ sign, but I should have said "match" not "capture".

    AFAIK javascript pretty much follows PCRE (Perl) syntax, so any problems you may have with PHP regex -> javascript is if you try to use POSIX syntax.


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
  •