Posted By

jamepaul on 09/07/10


Tagged

regex php validate


Versions (?)

Check Number


 / Published in: PHP
 

I want to get only number from user it does not start with zero. I think it's not perfect but works for me.

  1. function check_number($num) {
  2.  
  3. if ( $num[0] == 0 ) { // don't allow 0 start.
  4. return false;
  5. }
  6. if (preg_match("/^[0-9]+$/", $num)) {
  7. return true;
  8. } else {
  9. return false;
  10. }
  11.  
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: dbwebdev on September 8, 2010

function checknumber($num) { if (isnumber($num) & $num != 0) { return true; } else { return false; } }

Posted By: jamepaul on October 22, 2010

Yeah, thanks for your advance codes.

You need to login to post a comment.