I have a field that requires only numbers on one of my forms. Is there a function that would strip out all letters and just leave the numbers?
Thanks!
I have a field that requires only numbers on one of my forms. Is there a function that would strip out all letters and just leave the numbers?
Thanks!
[fphp]preg_replace[/fphp] would do it with an appropriate pattern.
<?php
preg_replace('~[^0-9]~', null, $string);
?>
I tried that and it didn’t work. I was still able to fill out the form with the following data:
123 E. Main
Shouldn’t the code snip that you provided reduced the string to:
123
Thanks
Rob
See http://au.php.net/manual/en/filter.filters.sanitize.php for what filters are available to sanitize input data in PHP and see http://au.php.net/manual/en/filter.examples.sanitization.php for an example of how to code it.