Common.php 582 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace api\models;
  3. use yii\base\Model;
  4. use yii\base\InvalidParamException;
  5. use common\models\User;
  6. /**
  7. * Password reset form
  8. */
  9. class Common extends Model
  10. {
  11. /**
  12. * 判断价格,保留两位小数
  13. * @param $str
  14. * @return int
  15. */
  16. static function is_price($str)
  17. {
  18. return preg_match('/^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/', $str);
  19. }
  20. /**
  21. * 验证手机号码
  22. * @return bool
  23. */
  24. static function is_tel($tel)
  25. {
  26. $istel = '/^1[34578][0-9]{9}$/';
  27. return preg_match($istel, $tel);
  28. }
  29. }