SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex validation

    I have numeric string of variable length i.e. from min 1 to max 15.

    I have validation code only that returns true(string) for completely supplied string like below

    Code JavaScript:
    var str = document.getElementById('txtCcNum').value; //2131-1111-2222-333
    var regex = /^2131[-]?\d{4}[-]?\d{4}[-]?\d{3}$/;
    alert(str.match(regex));  //returns the string

    This validation return string if I input full string, ie below 15 characters it returns null.
    ~~~~~~~
    But, my requirement is to validate above string that should starts with 2131 and rest of any numbers upto max 15 numeric chars.

    So, what is solution using regex validation?
    Last edited by phpFramework; Dec 10, 2007 at 21:23. Reason: No any replies.


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
  •