zoukankan      html  css  js  c++  java
  • PHP5中一个新的验证方法CTYPE

    可以专门针对字符串进行验证

    <?php
        if (!ctype_alnum($_GET['login'])) {
           echo "输入项必须为英文字符或数字0-9。";
        }
        if (!ctype_alpha($_GET['captcha'])) {
           echo "输入项必须为英文字符(大小写均可)";
        }
        if (!ctype_xdigit($_GET['color'])) {
           echo "输入项必须填写一个16进制数字。";
        }
    ?>

    还有检查大小写的
    <?php
    $strings 
    = array('aac123''qiutoas''QASsdks');
    foreach (
    $strings as $testcase) {
        if (
    ctype_lower($testcase)) {
            echo 
    "The string $testcase consists of all lowercase letters. ";
        } else {
            echo 
    "The string $testcase does not consist of all lowercase letters. ";
        }
    }
    ?> 

    检查空白字符的
    <?php
    $strings 
    = array('string1' => " "'string2' => " arf12"'string3' => ' ');
    foreach (
    $strings as $name => $testcase) {
        if (
    ctype_space($testcase)) {
            echo 
    "The string '$name' consists of all whitespace characters. ";
        } else {
            echo 
    "The string '$name' does not consist of all whitespace characters. ";
        }
    }
    ?>

  • 相关阅读:
    大学生自学网
    如何保证主从复制数据一致性
    CDN
    后端 线上 服务监控 与 报警 方案2
    利用 Gearman 实现系统错误报警功能
    增量部署和全量部署
    后端线上服务监控与报警方案
    简析TCP的三次握手与四次分手
    301 和 302 对 SEO 的影响
    Linux 查看负载
  • 原文地址:https://www.cnblogs.com/S-Ping/p/4133520.html
Copyright © 2011-2022 走看看