Tuesday 6 August 2013

To check whether a phone number field is valid, use:


bool is_numeric ( mixed $var )

Note that leading '+' or '-' signs are allowed.
http://php.net/manual/en/function.is-numeric.php

To replace all excess whitespace (new lines etc) use:

preg_replace("/\s+/", " ", $string);

To remove all leading and trailing spaces (but not extra spaces between words) use:

string trim ( string $str [, string $charlist = " \t\n\r\0\x0B" ] )

If you are using the "empty" function to detect blank fields, you must use trim to prevent spaces from being considered non-empty.
http://in3.php.net/manual/en/function.empty.php

No comments:

Post a Comment