LinuxÒÁµéÔ°ÂÛ̳'s Archiver

cabbac ·¢±íÓÚ 2005-9-15 14:55

ÈçºÎÓÃÕýÔò±í´ïʽÅжÏÊäÈëµÄ×Ö·û´®ÎªÕýÕûÊý

<html>
<head>
    <title>Untitled</title>
</head>

<body>
<?php
$in="2344";
if(ereg("^(-{0,1}|\+{0,1})[0-9]+(\.{0,1}[0-9]+)[GV_contentText]quot;,$in))
    echo "Ok!";
else
    echo "Sorry,Please input again!";
?>

</body>
</html>

ÉÏÃæÊÇÒ»¶ÎÀýÖ¤³ÌÐò£¬¹¦ÄÜÊÇÓÃÀ´ÅжÏÊäÈëµÄ×Ö·û´®ÊÇ·ñΪºÏ·¨Êý×Ö
²ËÄñÇë´óϺÏê½â ereg()²¿·Ö ÈçºÎÓøú¯ÊýÅжÏ×Ö·û´®ÊÇ·ñΪÕýÕûÊý£¿

ServerOnly ·¢±íÓÚ 2005-9-15 16:05

ÎÒ͵һµãÀÁ£º
[code]
<html>
<head>
<title>Untitled</title>
</head>

<body>
<?php
$in="2344";
if(ereg("^(-{0,1}|\+{0,1})[0-9]+(\.{0,1}[0-9]+)[GV_contentText]quot;,$in)) {
        echo "Ok! It is a number, ";
        print ((strrpos($in,'-') or strrpos($in,'.'))?"but it is not + int!":"and it is a + int!";
} else echo "Sorry,Please input again!";
?>

</body>
</html>
[/code]

µ±È»Õâ²»ÊǺð취

cabbac ·¢±íÓÚ 2005-9-15 16:13

ÈçºÎÖ±½ÓÓÃÕýÔò±í´ïʽÀ´ÅжÌÄØ£¿

ÓÃÕýÔò±í´ïʽÏÞÖÆÖ»ÄÜÊäÈëÊý×Ö£ºonkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

²ËÄñÎҲ鵽ÉÏÃæÒ»¶Îcode µ«²»ÖªÈçºÎ¼ÓÈëÒ³ÃæÖÐ...

ServerOnly ·¢±íÓÚ 2005-9-15 16:22

[code]
$str="12345";
print preg_match("/^(0|[1-9][0-9]*)$/", $str)?"$str is int.":"$str is not int.";
[/code]

ÒÔÉÏphpÎÒû²âÊÔ, µ«perlÎÒ²âÊÔÁË£º
[code]
#!/bin/perl
while (<>) {
        if ( $_ =~ /^([1-9][0-9]*)$/ ) {
                print "is int.\n";
                } else {
                print "is not int.\n";
        }
}
[/code]

cabbac ·¢±íÓÚ 2005-10-14 12:09

Çë½Ì °æÖ÷´ïÈËÒ»¸ö²ËÄñÎÊÌ⣺

ÔÚperl ±í´ïʽÖÐ $_ =~ /^([1-9][0-9]*)$/

Ó¦Óõ½php ÖÐ µÄÕýȷд·¨ÊÇÔõÑùµÄ£¿ÈçºÎ±íʾ¡°Æ¥Å䡱Ĩ£¿

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.