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 } 

demo


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -