Reputation: 1404
i want to add regular expression in $this->form_validation->set_rules()
but unable to find any correct solution for that.
as i want that my input field should only have 0 or 1 so how can i place inside setrules()
like
$this->form_validation->set_rules('binary', 'Binary', 'required|regexp_match[*//code..]');
thanks in advance
Upvotes: 1
Views: 199
Reputation: 7784
The expression should be like:
/^[01]{1}$/ OR /^[01]$/
Which corresponds to:
Only 1 or 0
Only one symbol allowed
So (updated delimiters):
$this->form_validation->set_rules('binary', 'Binary', 'required|regex_match[/^[01]{1}$/]')
Upvotes: 1