メールアドレスを確認しています。しかし、これは私が適切なTLDを使用しているかどうかを検証していません。.com、.in、.org、.govおよび.joに対してのみ検証したいのですが、どうすればよいですか?私のコードは次のようなものです:
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
}