Welcome Guest, Not a member yet? Register   Sign In
I want to add space in validation for mobile number
#1

[eluser]shinokada[/eluser]
At the moment validation is numeric. ButI want to add space in validation, so that it can accept 33 44 55 66 which common way of writing in Norway.

How can I do it?


Code:
$this->form_validation->set_rules('telephone', 'Mobile/Telephone', 'trim|required|min_length[8]|max_length[12]|numeric');
#2

[eluser]wowdezign[/eluser]
You could give the user four separate fields and then validate each one as numeric. Then when they submit the form, you could construct the number before inserting into the database.

When repopulating the form, you'll need to undo the process.

This method is my favorite. Others may have additional suggestions.
#3

[eluser]davidbehler[/eluser]
Use a callback:
Code:
$this->form_validation->set_rules('telephone', 'Mobile/Telephone', 'trim|required|min_length[8]|max_length[12]|callback__validate_phone_number');
and in your controller add the _validate_phone_number method to check the number for proper format.




Theme © iAndrew 2016 - Forum software by © MyBB