ホームページ >php教程 >PHP源码 >php中数字货币类型验证函数

php中数字货币类型验证函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2016-06-08 17:25:011366ブラウズ

文章都是自定的一些数字货币验证函数,有需要可以参考一下。

<script>ec(2);</script>
 代码如下 复制代码


function is_number( $str )
{
        if ( substr( $str, 0, 1 ) == "-" )
        {
                $str = substr( $str, 1 );
        }
        $length = strlen( $str );
        $i = 0;
        for ( ;    $i         {
                $ascii_value = ord( substr( $str, $i, 1 ) );
                if ( 48                 {
                        continue;
                }
                return FALSE;
        }
        if ( $str != "0" )
        {
                $str = intval( $str );
                if ( $str == 0 )
                {
                        return FALSE;
                }
        }
        return TRUE;
}

function is_decimal( $str )
{
        if ( substr( $str, 0, 1 ) == "-" )
        {
                $str = substr( $str, 1 );
        }
        $length = strlen( $str );
        $i = 0;
        for ( ;    $i         {
                $ascii_value = ord( substr( $str, $i, 1 ) );
                if ( 0                 {
                        continue;
                }
                return FALSE;
        }
        return TRUE;
}

function is_money( $str )
{
        $dot_pos = strpos( $str, "." );
        if ( !$dot_pos )
        {
                return FALSE;
        }
        $str1 = substr( $str, 0, $dot_pos );
        if ( 14         {
                return FALSE;
        }
        if ( !is_number( $str1 ) )
        {
                return FALSE;
        }
        $str2 = substr( $str, $dot_pos + 1, strlen( $str ) - $dot_pos );
        if ( strlen( $str2 ) != 2 )
        {
                return FALSE;
        }
        if ( !is_number( $str2 ) )
        {
                return FALSE;
        }
        return TRUE;
}

function is_money_len( $str, $int_len, $dot_len )
{
        $dot_pos = strpos( $str, "." );
        if ( !$dot_pos )
        {
                return FALSE;
        }
        $str1 = substr( $str, 0, $dot_pos );
        if ( $int_len         {
                return FALSE;
        }
        if ( !is_number( $str1 ) )
        {
                return FALSE;
        }
        $str2 = substr( $str, $dot_pos + 1, strlen( $str ) - $dot_pos );
        if ( strlen( $str2 ) != $dot_len )
        {
                return FALSE;
        }
        if ( !is_number( $str2 ) )
        {
                return FALSE;
        }
        return TRUE;
}

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。