Home > Backend Development > PHP Tutorial > php verification username problem

php verification username problem

WBOY
Release: 2016-08-08 09:06:42
Original
931 people have browsed it

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>
Copy after login

Regular Expressions

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

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~

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template