SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Regex help

  1. #1
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex help

    Hi...I need some help with JS regex....I have a lot of experience with regexps in PHP but I just don't get this one

    I need to have 16 chars(digits) which looks like this

    XXXXX-YYYYYYYYYY
    (5) - (10)

    So I have this:
    PHP Code:
                  var reg = new RegExp("/^[0-9]{5}-[0-9]{10}+$/");
                  
                  if(!
    reg.test(account_no.value))
                  { 
                              
    alert("bla!....");
                  } 
    but it doesnt' work

    I've tried replacing [0-9] with \d but still nothing....

    Any help would be appriciated....
    exit(0);

  2. #2
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it....I used search method....
    exit(0);

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In javascript it's handier to use regexps literals rather than constructors. If you're still using constructor, omit delimiters, ie

    Code:
    reg = new RegExp("^\d{5}-\d{10}$");
    
    or, preferred,
    
    reg = /^\d{5}-\d{10}$/

  4. #4
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the tip...

    I did it with your RegExp object rather than with search method...
    exit(0);


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
  •