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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?