我正在尝试为用户名,密码和电子邮件验证创建一个简单的正则表达式检查器。
要求如下:
用户名:
- Only letters and numbers (a-z, A-z, 0-9).
- No spaces, linebreaks, tabs or special characters.
- At least 5 characters in length.
- No more than 20 characters in length.
密码:
- At least 8 digits in length.
- no more than 40 characters in length.
- Must contain at least 1 special character or number.
电子邮件:
- Must follow the format "value@value.com".
这是我到目前为止所做的:
用户名 - 工作。
$username = $enteredUsername;
if(preg_match('/^[a-zA-Z0-9]{5,30}+$/', $username) == false ) {
echo "the username is invalid";
}
密码:尚未正常工作:
$password = $enteredPassword;
if(preg_match('/^[a-zA-Z0-9]+[\w0-9]{8,}+$/', $password) == false ) {
echo "the password is invalid";
}
电子邮件 - 工作。
$email = $enetered email.
if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) {
echo "the email is invalid";
}
电子邮件和用户名有效,但我似乎无法找出密码的正确正则表达式。
答案 0 :(得分:1)