php - Why doesn't my preg_match work? -


here php script:

<?php if (isset($_post['account'])) {     $str = $_post[account];     if ( !preg_match( "^[0-9]+$", $str ))     {         print "<p class=\"fadeout\" style=\"color:rgba(240, 240, 0, 1.0);\" >enter numbers only!</p>";     }     else     {         exec('"cmd /c echo weee!"');         print "<p class=\"fadeout\" style=\"color:rgba(240, 240, 0, 1.0);\" >your account has been added.</p>";     } } else {     if (isset($_post['account']) || $account == "") {         print "<form method=\"post\"><p>enter account number below.</p>";         print "<input name=\"account\" type=\"text\" size=\"15\" maxlength=\"7\"><input value=\"send\" type=\"submit\"></form>";     } } ?> 

i'm trying input visitors account number, want php verify if number inputted , action.

right now, shows input box , button, hitting submit button causes show "enter numbers only!" regardless of enter.

why isn't detecting numbers?

it seems me regex not right. try this:

if (!preg_match("/^[0-9]+$/", $str)) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -