Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular expression help

    Hello all,

    can someone tell me how can i verify that a string contains only english characters and/or numbers? Nothing else is acceptable.

    Thanks in advance.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What are english characters ?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want all the cahracters to be a-z, A-Z or 1-9. In other words i want the string to be an [[:alnum:]] . I want ALL the characters to be alnums. If any other character exists in the string (example @) i want the expression to return false. Please someone help me.

  • #4
    New Coder
    Join Date
    Jan 2004
    Location
    Los Angeles, California, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this might not be the best way, but i think it will work;
    PHP Code:
    <?
    $string 
    "Whatever string here for validation";
    if ( !
    eregi("^([A-Za-z0-9 ]+)$",$string) ) {
    die(
    "Not Valid.");
    }
    ?>
    ~imaekphp

  • #5
    New Coder
    Join Date
    Feb 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks it worked! I somewhat modified your code :

    $string = "fg34j29iaAArXfFGj92r";
    $x = ereg("^([[:alnum:]]+)$", $string);

    if($x){
    print "VALID";
    }else{
    print "not valid";
    }

    Thanks again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •