이메일 주소의 유효성을 검사합니다. 그러나 이것은 적절한 정보를 사용하고 있는지 여부를 검증하지 않습니다. .com, .in, .org, .gov 및 .jo에만 유효성을 검사하고 싶습니다. 어떻게해야합니까? 내 코드는 다음과 같습니다.자바 스크립트에서 이메일 주소의 TLD 유효성 확인
function validateConsumerEmail(){
email = document.getElementById('customer_email').value;
if ((email == null)||(email == "")){
alert("Please Enter a Valid Consumer Email Address...")
document.consumerEmail.customer_email.focus();
return false
}
if (echeck(email)==false){
email=""
document.consumerEmail.customer_email.focus();
return false
}
if(email != ''){
var splitting = email.split('@');
if(!isNaN(splitting[0])){
alert('Please provide proper email address...');
document.consumerEmail.customer_email.focus();
return false;
}
if(splitting[0].length<6 || splitting[0].length > 250){
alert('Please provide proper email address...');
document.consumerEmail.customer_email.focus();
return false;
}
}
}
여기서 customer_email은 필드 이름의 ID입니다.
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Please provide valid email ID.");
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Please provide valid email ID.");
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Please provide valid email ID.");
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Please provide valid email ID.");
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Please provide valid email ID.");
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Please provide valid email ID.");
return false
}
if (str.indexOf(" ")!=-1){
alert("Please provide valid email ID.");
return false
}
return true
}
'때는 isNaN (분할 [0]) '확인의 의미는 무엇입니까? 언제 'NaN'일까요? – alex
함수 echeck()의 내용을 볼 수 있습니까? – DaveHogan
분할 [0]. 길이 <6? 길이가 6 자 미만인 첫 번째 부분을 허용하고 싶지 않습니까? me @ 또는 mycase dave @는 유효하지 않습니다. – DaveHogan