PHP: How to Solve Laravel rules preg_match(): No ending delimiter ‘/’ found

### Instructions to
solve php-Laravel preg_match(): No ending delimiter’/’ found

1. The reason for
the problem is normally added as follows

1
2
3
4
5
6
public function rules()
{
    return [
        'domain'=>'required|regex:/^[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z]+$/'
    ];
}

 

Then when I tested the interface, I found that it kept reporting errors:

php-Laravel preg_match(): No ending delimiter’/’ found

Second, the solution is to
change the code to this

public  function rules()
{
    return [
         'domain'=>['required','regex:/^[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA- Z]+$/' ]
    ];
}

 

Then it’s normal

 

Similar Posts: