• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Pattern matching

Hi all,

How do I check if $from_mail is like:
[A-Za-z]([A-Za-z0-9]+)[0-9]"@mysite.com"
?

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 "@mysite.com".

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

Thanks!
0
slavikn
Asked:
slavikn
  • 2
1 Solution
 
TomeeboyCommented:
If that's the regex you want to match, then you can use preg_match:
http://us2.php.net/preg_match
0
 
TomeeboyCommented:

preg_match("/[A-Za-z]([A-Za-z0-9]+)[0-9]@mysite.com/", $matches);
if (isset($matches[0])) {
    echo "Pattern Matched";
} else {
    echo "Pattern NOT Matched";
}
0
 
slaviknAuthor Commented:
Thanks for your quick reply!!  (p.s. sorry for only 35 points - I have no points left at all :-()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now