作者:哎哟不错哦凉皮 | 来源:互联网 | 2024-10-24 14:23
本文旨在构建一个JavaScript函数,用于对用户输入的电子邮件地址和密码进行有效性验证。该函数将确保输入符合标准格式,并检查密码强度,以提升用户账户的安全性。通过集成正则表达式和条件判断语句,该方法能够有效防止常见的输入错误,同时提供即时反馈,改善用户体验。
What I want to do is establish a function in Javascript that will validate an inputted email and password, that checks the inputted email to make sure it has at least 2-3 characters after the last period in the string (for .com, .org, .ca, etc.) and that the string has at least one '@' symbol in it.
我想要做的是建立一个在Javascript函数,验证输入电子邮件和密码,检查输入电子邮件,以确保它至少有2 - 3字符字符串中的最后一段时间后(. com,.org,.ca等等),至少有一个“@”符号的字符串。
As for checking the password, I want the function to check that it has at least one lowercase and one uppercase letter, at least one number, and at least one special character (!,@,#,$,%,^,&,*,~)
至于检查密码,我希望功能检查,至少一个小写字母,一个大写字母,至少一个数字,至少一个特殊字符(! @、# $,%,^,&、* ~)
Does anyone know what I would have to do to get the regular expression to check the password for at least 1 special character like !, @, *, etc.?
有人知道我要做什么才能让正则表达式检查至少一个特殊字符的密码,比如!,@,*等等?
Here's what I have:
这就是我有:
function validatePassword(password)
{
var passwordPattern = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/;
return passwordPattern.test(password)
}
// Validate form
function validate()
{
var email = user.email.value;
if(validateEmail(user.email.value))
user.validEmail.value = "OK";
else
user.validEmail.value = "X";
if(validatePassword(user.password.value))
user.validPassword.text = "OK";
else
user.validPassword.text = "X";
}
3 个解决方案