我有这个代码:
$string1 = "My name is 'Kate' and im fine";
$pattern = "My name is '(.*)' and im fine";
preg_match($pattern , $string1, $matches);
echo $matches[1];
Run Code Online (Sandbox Code Playgroud)
当我运行它时会返回此错误:
警告:preg_match()[function.preg-match]:分隔符不能是字母数字或反斜杠
我想用@ mywork.com限制我的电子邮件注册我在My_Form_validation中做了以下内容.
public function email_check($email)
{
$findme='mywork.com';
$pos = strpos($email,$findme);
if ($pos===FALSE)
{
$this->CI->form_validation->set_message('email_check', "The %s field does not have our email.");
return FALSE;
}
else
{
return TRUE;
}
}
Run Code Online (Sandbox Code Playgroud)
我用它如下.我对用户名和密码使用CI规则,它适用于电子邮件,它接受任何电子邮件地址.任何我感谢任何帮助.
function register_form($container)
{
....
....
/ Set Rules
$config = array(
...//for username
// for email
array(
'field'=>'email',
'label'=>$this->CI->lang->line('userlib_email'),
'rules'=>"trim|required|max_length[254]|valid_email|callback_email_check|callback_spare_email"
),
...// for password
);
$this->CI->form_validation->set_rules($config);
Run Code Online (Sandbox Code Playgroud)