SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex Help Requied

    Hello

    I know Javascript, but when it comes to Regex, i m not good at it.

    I need a javascript code based on regex that can check if the data in a text box is like this format :

    Code:
    9AA 
    
    Means, first character must be a DIGIT and the last 2 must be ALPHABETS.
    Next, the other text box must have data like below format.

    Code:
    A9
    A99
    AA9
    AA99
    A9A
    AA9A
    Please support.

    Thanks
    ZH

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    /^\d[^A-Z0-9]*[A-Z]{2}$/
    
    /^[A-Z]{1,2}\d{1,2}[A-Z]?$/
    Tab-indentation is a crime against humanity.

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Ali !

    In your pattern :

    /^\d[^A-Z0-9]*[A-Z]{2}$/

    the first A-Z0-9 means it can have alphabets and numbers, so if I only want numbers there, can i make it :

    /^\d[^0-9]*[A-Z]{2}$/

  4. #4
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly, that would only accept numbers, not letters for the first character. Everytime you use a hyphen, regex includes everything in between the respective Unicode code points; since capital letters, lower-case letters, and numbers each have contiguous spots, you can call each group together.

    U+0030{0}-U+0039{9}
    U+0041{A}-U+005A{Z}
    U+0061{a}-U+007A{z}

    If you look over the Unicode charts you can include any set of contiguous characters in this way.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great !

    Thank you all .


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
  •