2017-10-16 2 views
2

입력란에서 여러 개의 이메일을 확인하는 중입니다. 실제로 Regex를 사용할 수는 없습니다.자바 스크립트에서 한 번에 여러 이메일을 확인하는 방법은 무엇입니까?

@ email.comuser2 @ gmail.com, [email protected] USER1 : 나는 쉼표, 세미콜론, 공백으로 구분하여 이메일과 때로는 공백없이, 이런 일이있는 입력 필드가 ; [email protected] [email protected] 내가 정규식을 사용하여 모든 이메일을 얻으려고 노력하고 그들 각각의 유효성을 검사하지만, 자바 스크립트에서 정규식을 사용하여 작업을 수행하는 방법에 정말 잘 모르겠어요

.

나는 자바에 내 코드를 작성하고 그것을 모든 이메일 얻기에 좋은 작품 :

자바 코드 :

이제

String employeeEmails = "[email protected] , [email protected] [email protected];[email protected]"; 

Matcher eachEmail = Pattern.compile("\\[email protected]\\w+.com").matcher(employeeEmails); 
List<String> emailList = new ArrayList<String>(); 

while (eachEmail.find()){ 
    emailList.add(eachEmail.group()); 
} 

마지막으로 이메일 목록이이 모든 이메일을 I Javascript에서 모든 이메일을 가져 와서 각각의 유효성을 검사하려고 시도하는 중 하나가 유효한 이메일이 아닌 경우 오류가 발생합니다.

자바 스크립트 :

var regex1 = /\[email protected]\w+.com/; // This will get all emails from inputField 
    var emailList = regex1; 
    var regex2 = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/; // This will validate each email 

    for(var i = 0;i < emailList.length;i++) { 
     if(!regex2.test(emailList[i])) { 
      return me.invalidText; // throw error if an email is not valid 
     } 
    } 

이 자바 스크립트에서 수행하는 데 필요한 다음은 내 코드입니다. 아무도 내가 누락 된 걸 말해 줄 수 있니? 미리 감사드립니다.

답변

0

나는이 도움이 당신을 희망 :

employeeEmails = "[email protected] , [email protected] [email protected];[email protected]*[email protected]"; 

function extractEmails(x) { return x.match(/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/g); } 

var emails=extractEmails(employeeEmails); 

    // The emails already in an array, now a more exhaustive checking: 

function validateEmail(v) { var regex = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 
    return regex.test(v); 
} 

emails.forEach(function(email, index) 
{ 
    // Here you can handle each employee emails. 
    // 
    // Example: 
    var verified=validateEmail(email); 
    document.write(' validation is '+ verified +' for '+ email +'<br>');  
}); 

출처 :

관련 문제