studentofstone Posted January 10, 2011 Share Posted January 10, 2011 Hi I'm trying to strip all punctuation and validate a phone number after entering a number I get. the other question I have is how to get the validation part to only respond if there is no match I tried if( !preg_match..... but it didn't work Compilation failed: range out of order in character class at offset 8 on this line $phone = preg_replace( "/[$punctuation]/", '', $_REQUEST[ 'number' ] ); here is the code around it. $punctuation = preg_quote( "().- "); $phone = preg_replace( "/[$punctuation]/", '', $_REQUEST[ 'number' ] ); $valid = "/[1?][2-9][0-9]{2}[2-9][0-9]{2}[0-9]{4}/"; if ( preg_match( $valid, $number ) == 1 ) { echo( "${_REQUEST[ 'number' ]} is valid<br />" ); } Quote Link to comment Share on other sites More sharing options...
mikecampbell Posted January 11, 2011 Share Posted January 11, 2011 Try this. $phone = preg_replace( "/[\(\)\.\- ]/", '', $_REQUEST[ 'number' ] ); $valid = "/^[1?][2-9][0-9]{2}[2-9][0-9]{2}[0-9]{4}$/"; if ( preg_match( $valid, $phone ) == 0 ) { echo( "${_REQUEST[ 'number' ]} is NOT valid<br />" ); } Quote Link to comment Share on other sites More sharing options...
studentofstone Posted January 12, 2011 Author Share Posted January 12, 2011 Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.