PHP Regex preg_match Email Validation -
$email = 'john@business.com'; if(preg_match(\w+(@business.com)\z), $email){code goes here}
i'm trying execute code in "code goes here" section of condition when $email contains email address ends in @business.com
.
i feel i'm perhaps misunderstanding how preg_match
works, can't find information why if statement evaluating false.
there many, many examples , other people having similar problems, solution problems doesn't seem highlight issues code.
i working off example:
http://php.net/manual/en/function.preg-match.php
<?php // "i" after pattern delimiter indicates case-insensitive search if (preg_match("/php/i", "php web scripting language of choice.")) { echo "a match found."; } else { echo "a match not found."; } ?>
no need use regex
can use strstr
function of php as
if(strstr('xyz@business.com',"@") == "@business.com"){ // code goes here }
or using regex can use positive lookbehind as
if(preg_match('~(?<=\w)(@business.com)~',$string)!==false){ // code goes here }
Comments
Post a Comment