Home  >  Article  >  Backend Development  >  php verification username problem

php verification username problem

WBOY
WBOYOriginal
2016-08-08 09:06:42888browse

PHP username verification must be within 5 to 15 characters, and can only be letters, numbers, and underscores

Reply content:

PHP username verification must be within 5 to 15 characters, and can only be letters, numbers, and underscores

You can use regular verification, refer to the following

<code>/**
 * description 用户名验证
 */
final public static function isName($val) {
    try {
        $pattem = "/^[a-zA-Z0-9_]{5,15}$/";
        if (preg_match ( $pattem, $val )) {
            return $val;
        } else {
            return false;
        }
    } catch ( Exception $e ) {
        throw $e;
    }
}</code>

Regular Expressions

<code>(\w|\d){5,15}/u</code>

In fact, all regular rules can be used universally~ It’s just that the calling method is different~ The rules I wrote in Swift are the same as those written in the front end, but the final judgment method of calling is different~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn