CIサポートのGrocery CRUDでアプリケーションを開発していますが、検証が認識されないときに、フィールドがアルファベット文字、ポイント、カンマ、スペースだけを受け入れることが検証されますが動作しません:私は、関数solo_letras呼んで食料品CRUDの関数のコードのCodeigniterの文字を検証する
ライン:
Lines of code in method of Grocery CRUD
をVAれるもの服用することができる蓋?
CIサポートのGrocery CRUDでアプリケーションを開発していますが、検証が認識されないときに、フィールドがアルファベット文字、ポイント、カンマ、スペースだけを受け入れることが検証されますが動作しません:私は、関数solo_letras呼んで食料品CRUDの関数のコードのCodeigniterの文字を検証する
ライン:
Lines of code in method of Grocery CRUD
をVAれるもの服用することができる蓋?
CodeIgniterで組み込みのフォーム検証を使用します。 私はこれを好きです。これは、ユーザー名フィールドのためのサンプルです
$this->form_validation->set_rules('inputFirstName', 'First Name', required|min_length[4]|max_length[16]|is_unique[users.username]');
:あなたの関数の開始時に はこのようなフォームの入力のためのすべてのルールを設定します。最初のパラメータはフォーム入力name='inputFirstName'
です.2番目のパラメータは、最初のものを読み込み可能なバージョンで、エラー報告に使用されます。その後、パイプ文字で区切られた検証が行われます。一致する正規表現の検証があります。 regex_match[/regex/]
。
if($this->form_validation->run() == false) {
Do something here if validation fails
return false;
}
検証のためにテストするには:すべてのあなたの検証が、その後使用
場所。 その後、検証に合格したらコードを続行します。ここで
は、簡単な登録機能の完全なサンプルです:
public function register()
{
$this->output->set_content_type('application_json');
$this->form_validation->set_rules('inputUsername', 'User Name', 'required|min_length[4]|max_length[16]|is_unique[users.username]');
$this->form_validation->set_rules('inputEmail', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('inputFirstname', 'First Name', 'required|max_length[20]');
$this->form_validation->set_rules('inputLastname', 'Last Name', 'required|max_length[20]');
$this->form_validation->set_rules('inputPassword', 'Password', 'required|min_length[6]|max_length[16]|matches[inputPasswordConfirm]');
$this->form_validation->set_rules('inputPasswordConfirm', 'Password Confirmation', 'required');
if($this->form_validation->run() == false) {
$this->output->set_output(json_encode(['result' => 0, 'error' => $this->form_validation->error_array()]));
return false;
}
$username = $this->input->post('inputUsername');
$email = $this->input->post('inputEmail');
$firstName = $this->input->post('inputFirstname');
$lastName = $this->input->post('inputLastname');
$password = $this->input->post('inputPassword');
$passwordConfirm = $this->input->post('inputPasswordConfirm');
$this->load->model('user_model');
$user_id = $this->user_model->insert([
'username' => $username,
'email' => $email,
'firstName' => $firstName,
'lastName' => $lastName,
'password' => hash('sha256', $password . PASSWORD_SALT)
]);
if($user_id) {
$this->session->set_userdata(['user_id' => $user_id]);
$this->output->set_output(json_encode(['result' => 1]));
return false;
}
$this->output->set_output(json_encode(['result' => 0, 'error' => "User not created."]));
}
私は理解しますが、私は必要なものだけ次の文字{[スペース]に加えてからZまでの文字を受け入れるようにフィールドの検証です。 、} –
ここには素晴らしい正規表現テストサイトがあります。 http://www.regexr.com/ – Dominofoe
申し訳ありませんが、他の1桁の数字が含まれています。これはあなたが望むものです。 '/ [a-z、A-Z \ s \。\、]/g' – Dominofoe