duanmu2015 2014-07-10 08:43
浏览 58
已采纳

PHP Regex用于字体大小限制

I'm having some trouble with Regex never really used it. However basically I'm trying to set a limit on my font-size bbcode tag.

class SizeValidator implements \JBBCode\InputValidator
{

public function validate($input)
{
    return (bool) preg_match('regex', $input);
}

}

If someone can help with the regex that'll be perfect! Basically just want Size 7 to 30 max, no px, em, nothing strictly numbers max 2 numbers if anyone with regex experience would be quite helpful possibly explain how it works so I can improve and get a better understanding :)

  • 写回答

2条回答 默认 最新

  • dsfdsf46465 2014-07-10 08:47
    关注

    There really is no reason to use regular expressions here.

    Simply verify that what you're getting is a sequence of digits (for instance using ctype_digit, and that the value lies between 7 and 30.

    class SizeValidator implements \JBBCode\InputValidator {
        public function validate($input) {
            return ctype_digit($input) && $input >= 7 && $input <= 30;
        }
    }
    

    It's much more readable and easier to modify if need be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据