how to add a custom validation , codeigniter

3.4k Views Asked by At

hi i am using codeigniter , i use codeigniter form validation . i have a input called price

<input id="Price"  name="price" class="textbox-small Verdana11-424039" type="text" name=""
 tabindex="1900" />

i validate price like this

this->form_validation->set_rules('price', 'Price', 'trim|required'); 

but i want to validate price to take only numbers , commas and dots

like this .

1000
1000.00
1,000.00

how can a custom validation like this accomplished by codeigniter , please help......

1

There are 1 best solutions below

0
On BEST ANSWER

There is a callback function option when using form validation in codeigniter. You can write your own function inside the controller which checks for your price using regex, and then you can set that function/method as the callback function name when you set form validation rules.

You can read more at http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks