首頁 >php教程 >PHP源码 >php中数字货币类型验证函数

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-08 17:25:011363瀏覽

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

<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