Java to determine whether email is legitimate

Source: Internet
Author: User
Tags valid email address

/*** Check if the email address is legal *@paramEmail *@returntrue Legal false not valid*/  Importjava.util.regex.*;//a processing class that provides regular expressions in the package Public classhello{ Public Static voidMain (String[]args) {String email= "[Email protected]";      SYSTEM.OUT.PRINTLN (email);         Validate (email); }Private Static BooleanValidate (String email) {BooleanIsexist =false; /*in the regular expression \w means that any single character range is a-z,a-z,0-9, because in Java \ is an escape symbol, if only write as \w will be ambiguous, or even error, so write as: \\w+ means to appear more than once, so \\w+ Represents a string of any length, but does not include other special characters such as _,-, $,&,*, etc.*///(\\w+.) + indicates that the server may have a multilevel domain name, [a-z]{2,3} indicates a maximum of 2-3 domain names.     /*Pattern p = pattern.compile ("\\[email protected" (\\w+.)      +[a-z]{2,3} ");      Matcher m = p.matcher (email);  Boolean B = m.matches (); *///The first method of presentation    if((Pattern.matches ("\\[email protected") (\\w+.) +[a-z]{2,3} ", email))) {System.out.println ("Valid email address"); Isexist=true; } Else{System.out.println ("Invalid email address"); }      returnisexist; }  }

Java to determine whether email is legitimate

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.