2013-05-01 1 views
1

RegExp 패턴을 검색하여 Javascript에서 전자 메일 주소의 유효성을 검사 할 때 Facebook에서 사용하는 패턴을 here에서 찾았습니다.Facebook 등록 양식 전자 메일 유효성 검사 패턴

function is_email(a){return /^([\w!.%+\-])[email protected]([\w\-])+(?:\.[\w\-]+)+$/.test(a);} 

누군가이 패턴이 어떻게 작동하는지 설명해 주시겠습니까? 나는 '@'문자와 함께 3 자리에서 '단어 문자'를 찾고 있음을 이해합니다. 그러나 좋은 설명은 나를 이해하는 데 많은 도움이 될 것입니다.

+2

다음은 정규식 패턴에 대한 더 유용한 설명을 생성하는 두 개의 웹 사이트입니다. http://www.regexper.com/ 및 http://regex101.com/ –

+1

감사합니다! 그거야. 그 내용을 답으로 쓰고 싶으면 받아 들여서 기쁩니다. – user

답변

0

정규식 패턴에 대한 설명을 생성하는 두 개의 웹 사이트가 있습니다.

^  # anchor the pattern to the beginning of the string; this ensures that 
     # there are no undesired characters before the email address, as regex 
     # matches might well be substrings otherwise 
(  # starts a group (which is unnecessary and incurs overhead) 
    [\w!.%+\-] 
     # matches a letter, digit, underscore or one of the explicitly mentioned 
     # characters (note that the backslash is used to escape the hyphen 
     # although that is not required if the hyphen is the last character) 
)+  # end group; repeat one or more times 
@  # match a literal @ 
(  # starts another group (again unnecessary and incurs overhead) 
    [\w\-] # match a letter, digit, underscore or hyphen 
)+  # end group; repeat one or more times 
(?:  # starts a non-capturing group (this one is necessary and, because 
     # capturing is suppressed, this one does not incur any overhead) 
    \.  # match a literal period 
    [\w\-] # match a letter, digit, underscore or hyphen 
    +  # one or more of those 
)+  # end group; repeat one or more times 
$  # anchor the pattern to the end of the string; analogously to^

그래서, 이것은 약간의 최적화 된 버전을 다음과 같습니다

패턴에 대한 내 자신의 설명이되어 있으므로 그래픽 않는 단어

  • regexper.com의 패턴을 설명 :

    /^[\w!.%+\-][email protected][\w\-]+(?:\.[\w\-]+)+$/ 
    
  • 관련 문제