开发者

Check if string contains no characters except numbers?

I need to check if a string contains NO other characters except numbers (0,1,2,3,4,5,6,7,8,9).

开发者_StackOverflow中文版

I'm expecting the user to input a time (12:00). I explode() the input to seperate the hours and minutes. I now need to make sure the time is an actual time value.

$time = explode(":",$time);

if ($time['0'] > 12 || $time['0'] < 1 || not_actual_numbers)
{
    //error: not valid hour
    echo("error: time val hour is bad");
}


You can use is_int

$time = explode(":",$time);

if ($time['0'] > 12 || $time['0'] < 1 || !is_int($time[0]))
{
    //error: not valid hour
    echo("error: time val hour is bad");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜