regex - preg_match to only allow 10 digits an no special characters or spaces -


i have following function: preg_match('/^[0-9]{10}$/' allow 10 digits. how ever if enter 041 123456 accepts it. how prevent spaces? want user enter phone number 041123456 only. no spaces or special characters must allowed.

the code using

if( ($fax_1_length != 0) | preg_match('/^[0-9]{10}$/', $fax_1) ){     $fax_1_lenght_valid = true;     $fax_1 = mysql_real_escape_string(stripslashes($_post['fax_1']));        }     else     {             $mistakes[] = 'error - 1st fax number should contain numbers or empty.';     } 

problem line:

if( ($fax_1_length != 0) | preg_match('/^[0-9]{10}$/', $fax_1) ) 

| used bitwise oring.

you should using && instead of |

if( ($fax_1_length > 0) && preg_match('/^[0-9]{10}$/', $fax_1) ) 

which execute if block when length > 0 && phone number contains 10 digits only.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -