I wanted a simple regex phone validation for WordPress plugin Contact Form 7. The validation had to be in the form of xxx-xxx-xxxx.
I ran across a blog page by Eric Holmes. He was learning regex at the time, but did a superb job. The link is: http://ericholmes.ca/form-validation-in-php-simplified/
He has since updated his original post at: http://ericholmes.ca/php-phone-number-validation-revisited/
So, in the Contact Form 7 formatting.php module, replace:
function wpcf7_is_tel( $tel ) { $result = preg_match( '/^[+]?[0-9() -]*$/', $tel ); return apply_filters( 'wpcf7_is_tel', $result, $tel ); } with: function wpcf7_is_tel( $tel ) { $result = preg_match( '/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i', $tel ); return apply_filters( 'wpcf7_is_tel', $result, $tel ); }