php创建验证码
When I create login areas (mostly intranets) for small websites, I'm always asked by the customer to keep usernames to letters and numbers. That means no email addresses as usernames and special characters like "_", "-", and ".". This, in my customer's mind, keeps the login easy for their users and limits the number of support calls they will receive. While I don't recommend disallowing common username characters like the ones cited above, I do understand their need for simplicity. Here's how, using PHP, I validate that a username is only letters and numbers.
当我为小型网站创建登录区域(主要是内部网)时,客户总是要求我将用户名保留为字母和数字。 这意味着没有电子邮件地址作为用户名和特殊字符(如“ _”,“-”和“。”)。 在我的客户看来,这使他们的用户易于登录,并限制了他们将收到的支持电话的数量。 尽管我不建议您禁止使用上述常见的用户名字符,但我确实理解它们对简单性的需求。 使用PHP验证用户名只是字母和数字的方法如下。
PHP (The PHP)
function validate_username($input,$pattern = '[^A-Za-z0-9]'){ return !ereg($pattern,$input);}
It's as easy as that. I don't go as far as using this for passwords, but you could if you wanted to. I'll also mention that if I want to allow non-alphanumeric characters, I just need to change the function's pattern. Easy enough!
就这么简单。 我不打算将其用作密码,但是如果您愿意,可以这样做。 我还要提到,如果要允许使用非字母数字字符,则只需要更改函数的模式即可。 很简单!
翻译自:
php创建验证码