I am trying to stop people from accidentally entering dashes and spaces into the credit card field.

If they do, and the javascript doesn't catch them - probably due to js being turned off, then I plan to just take the dashes and spaces out.

Here's what I have so far:

str_replace(' ','',$_POST['creditCard'])

That takes care of the spaces, but not dashes. Is there a way to take out both within the str_replace function at once?

    Use preg_replace() if you want to do that. In fact, you might as well strip out everything that is not a digit.

      You could use str_replace to remove spaces and dashes at once, but giving it an array of strings to search for, but if you go with laserlight's advice (and people will enter any old thing into any field they find, so it's a good idea) then the regular expression would be a lot simpler.

        Write a Reply...