简体   繁体   English

php ereg验证表格

[英]Php ereg validating a form

Im validating a form and its easy to validate numbers, letters az and so on but when i got to the point where i need to validate a field which must contain only the characters (az and special characters such as öçğüiş) with at least one space only I am really stuck! 我正在验证表单及其易于验证的数字,字母az等,但是当我到达需要验证必须仅包含字符(az和特殊字符,例如öçğüiş)且至少包含一个空格的字段时,只有我真的被卡住了!

I tried the following and some other techniques without success: 我尝试了以下方法和其他一些方法,但均未成功:

function validateAlphaSpecial($value) {
    if (ereg("/^[\p{L}\s]+$/", $value, $regs)) {
           echo 'true';
         } else {
           echo 'false';
        } 
}

Has anyone got a solution for this. 有没有人对此有解决方案。 Thank you. 谢谢。

Ereg has been deprecated as of PHP 5.3.0 like others said and you shouldn't use EREG. 正如其他人所说, Ereg自 PHP 5.3.0 起已被弃用 ,您不应该使用EREG。

The snippet below fits your validating requirement: az and special characters such as öçğüiş with at least ONE SPACE . 以下代码段符合您的验证要求: az和特殊字符(例如öçğüiş至少带有一个SPACE)

if( preg_match("/[\p{L}]\s{1,}+/u", $value) > 0 ) {
    echo 'Valid';
} else {
    echo 'Not valid';
}

About /u modifier [ from documentation ] : 关于/ u修饰符 [来自文档 ]:

This modifier turns on additional functionality of PCRE that is incompatible with Perl. 此修改器打开了与Perl不兼容的PCRE的其他功能。 Pattern strings are treated as UTF-8. 模式字符串被视为UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM