Javascript/Default

email 체크

선우아범 2015. 8. 26. 16:00

function emailCheckBoolean(obj){

 var result = "true";

 if (obj.value == "" || obj.value == null){

  obj.focus();

  result = "false";

 } else {

  var email_addr = obj.value;

  var location1 = obj.value.indexOf('@',0) +1;

  if (location1 == 0){

   obj.value = "" ;

   obj.focus();

   result = "false";

  } else{

   var location2= obj.value.indexOf('.',0)+1;

   if (location2 == 0) {

    obj.value = "" ;

    obj.focus();

    result = "false";

   }

  }

  var i, strTestemail01;

  strTestemail01 = email_addr;

  if(strTestemail01.charAt(email_addr.length-1)=='@' || strTestemail01.charAt(email_addr.length-1)=='.'){

   obj.value = "" ;

   obj.focus();

   result = "false";

  }

  for (i=0; i<email_addr.length; i++){

   if( strTestemail01.charAt(i) >= 'a' && strTestemail01.charAt(i) <= 'z' )

    continue;

   if( strTestemail01.charAt(i) >= 'A' && strTestemail01.charAt(i) <= 'Z' )

    continue;

   if( strTestemail01.charAt(i) >='0' && strTestemail01.charAt(i) <='9')

    continue;

   if( strTestemail01.charAt(i) == '-' || strTestemail01.charAt(i) == '_' ||  strTestemail01.charAt(i) == '@' ||  strTestemail01.charAt(i) == '.')

    continue;

   obj.value = "" ;

   obj.focus();

   result = "false";

  }

 }

 return result;

}