本文介绍了如何检查真实姓名和姓氏 - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:我想检查用户是否插入了真实姓名和姓氏,方法是检查他们是否只有字母(任何字母表)和 ' 或 - 在 PHP 中.我在这里找到了一个关于如何检查字符串是否只有字母的解决方案(但我不记得链接了):

here's my problem:I want to check if a user insert a real name and surname by checking if they have only letters (of any alphabet) and ' or - in PHP.I've found a solution here (but I don't remember the link) on how to check if a string has only letters:

preg_match('/^[\p{L} ]+$/u',$name)

但我也想承认 ' 和 - 也是.(字符集为 UTF8)有人可以帮我吗?

but I'd like to admit ' and - too. (Charset is UTF8)Can anyone help me please?

推荐答案

看来你只需要修改正则表达式:[\p{L}' -]+

Looks like you just need to modify the regex: [\p{L}' -]+

这篇关于如何检查真实姓名和姓氏 - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 21:09