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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:25:011363Durchsuche

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

<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;
}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn