SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Regular Expression

  1. #1
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expression

    Hello all.

    I need some help regarding regular expression.

    I'm creating a form in which there is field which should be filled by 10 character long alpha-numeric value.

    Now I want to check whether that is in correct order or not. But I'm unable to create any regular expression to check that.

    In that character the first five character should be alpha, then the next 4 character should be numeric and the last one should be again an alpha.

    Please help me.

  2. #2
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried to make one.

    Tell me whether it is right or not.

    PHP Code:
    [A-Z]{5}\d{4}[A-Z]{1

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,109
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    if(=== preg_match('~^[a-z]{5}[0-9]{4}[a-z]$~i'$field)){
        
    #valid
    }
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I'm trying to validate it by using the code.

    I'm getting error. can any body rectify why I'm getting error ?
    PHP Code:
    <?php
    $pattern 
    "[A-Z]{5}\d{4}[A-Z]{1}";
    $PAN"AXYTR2347E";

    if(
    preg_match($pattern$PAN))
    {
        echo 
    "Successfull.";
    }
    else
    {
        echo 
    "Not able to make";
    }
    ?>
    Error Message is:

    Warning: preg_match() [function.preg-match]: Unknown modifier '{' in D:\wamp\www\spa\pantest.php on line 13

  5. #5
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    PHP Code:
    <?php
    if(=== preg_match('~^[a-z]{5}[0-9]{4}[a-z]$~i'$field)){
        
    #valid
    }

    Thanx Anthony.

    Solved the issue now.

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
  •