dtc88867 2013-01-24 22:19
浏览 42
已采纳

utf-8的preg_match规则

what pregmach rule i must use for full_name field?
i want user input only character and not html or php code value and space between 3 to 11 character
i can use:

<?php
if (preg_match("%^[A-Za-z0-9-_]{3,10}$%", $_REQUEST['usr'])) {
//do something like 
mysql_query('insert into user(name) values(this field)');
//damn what is this for: It does not meet our quality standards.!!!
//i must insert more code? i dont have ! let me go !
}
else{
//do something else!
die('get out !:D');
}
?>

but with this user cant input UTF-8 characters like "مسیح ارسطوئی"
so what preg_match rule i must use for UTF-8 ?
or what other code like preg_match i can use ?
I WANT USER JUST Can insert characters not <>{}[] or $%^&*
between 3 to 10 character !!! thanks

  • 写回答

3条回答 默认 最新

  • dongyao1915 2013-01-24 23:24
    关注

    This will give "0", cos مسیح ارسطوئی is not containing only 3-10 chars;

    $x = preg_match('~^([\pL]{3,10})$~u', 'مسیح ارسطوئی');
    echo $x ? 1 : 0;
    

    But this gives a result in your case;

    preg_match('~([\pL]+)~u', 'مسیح ارسطوئی', $m);
    print_r($m);
    
    Array
    (
        [0] => مسیح
        [1] => مسیح
    )
    

    See more details here: PHP: Unicode character properties

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了