Tôi mới vào JavaScript và tìm thấy mã JavaScript này trong internet mà xác nhận email được cung cấp (không có vấn đề với mã) -xác nhận email hiểu biết sử dụng JavaScript
<html>
<h2>Email Validation</h2>
<script language = "Javascript">
function checkEmail(emailId) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailId)){
document.write("You have entered valid email.");
return true;
}
return false;
}
function ValidateEmail(){
var emailID=document.form.email;
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (checkEmail(emailID.value)==false){
emailID.value=""
alert("Invalid Email Adderess");
emailID.focus()
return false
}
alert('valid');
return true
}
</script>
<form name="form" method="post" onSubmit="return ValidateEmail()">
Enter an Email Address : <input type="text" name="email" size="30"><br>
<input type="submit" name="Submit" value="Submit">
</form>
</html>
Tôi không có vấn đề với mã này, nhưng Tôi bằng cách nào đó không hiểu những gì biểu thức chính quy /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
có nghĩa là. Tôi không hiểu ý nghĩa của từng phần biểu hiện chính quy. Vui lòng làm sáng tỏ cho tôi.
Bạn nghĩ rằng điều đó gây nhầm lẫn ... hãy thử cách này: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html. Việc xác thực email w/regex là khó khăn ... xem: http://programmers.stackexchange.com/questions/78353/how-far-should-one-take-e-mail-address-validation –