Pattern matching

Posted on 2006-03-24
Last Modified: 2011-10-03
Hi all,

How do I check if $from_mail is like:

Comments: the check is performed after I know $from_mail looks like a correct e-mail address.
So I want to know if it starts with a letter, then alphanumeric chars, then a digit, then "".

The code should look like:
if (cond):
   echo '<strong>Pattern matched!</strong><br>';
   echo '<strong>Pattern did NOT match!</strong><br>';

Question by:slavikn
    LVL 15

    Accepted Solution

    If that's the regex you want to match, then you can use preg_match:
    LVL 15

    Expert Comment


    preg_match("/[A-Za-z]([A-Za-z0-9]+)[0-9]", $matches);
    if (isset($matches[0])) {
        echo "Pattern Matched";
    } else {
        echo "Pattern NOT Matched";
    LVL 1

    Author Comment

    Thanks for your quick reply!!  (p.s. sorry for only 35 points - I have no points left at all :-()

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now