• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to remove special characters

#1
[eluser]Wondering Coder[/eluser]
hello to everyone

just would like to ask how to remove this: -, [], / or any special characters in my input

tried setting rules in validation using xss_clean but it still it save those character.

e.g input:
1111-1-1111 = must only save 111111111
2222/2/2222 = must only save 222222222
2222#222#22 = must only save 222222222

etc….

#2
[eluser]Anonymous[/eluser]
Use a callback on the input field. Then in the callback function use a regex.

#3
[eluser]boltsabre[/eluser]
sounds good to me... but make sure you do all your other validation before you make your call back. i.e.

Code:
$this->form_validation->set_rules('phoneNumber', 'Phone Number', 'trim|required|min_length[8]|myCustomCallBack

As regex can be quiet taxing in processing power/time. Get your input as close to validated before applying your regex to save a little overhead. It may seem trivial now, but it's a good habit to get into, especially for larger applications and complex regex stuff


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.