Verify that the mailbox format is legitimate (Java code implementation)

Source: Internet
Author: User

First, verify that the e-mail address meets the following requirements:

1. There is only one @

[email protected] cannot be placed at the beginning or the end

[email protected] must be followed by a "."

[email protected] cannot be followed before or after "."

[email protected] to have 6 characters before

6. End with COM, org, CN, net

Second, the code implementation: 1. Implementing code
 PackageHomework3; //e-mail inspection is qualified Public classCheckemail { Public Booleanisemail (String email) {//determine if the mailbox is empty         intK = 0; if(Email = =NULL) {             return false; }         /** Single quotation mark data is a char type double quotation mark data is of type string Single quotation marks can only be quoted one character and double quotation marks may be cited 0 and above **/         //determine if there is only one @ and cannot start or end         if(Email.indexof ("@") > 0 && email.indexof (' @ ') = = Email.lastindexof (' @ ') && email.indexof (' @ ') < Email.length ()-1) {k++; }                 //you must have "." After judging "@" and cannot follow         if(Email.indexof ('. ', Email.indexof (' @ ')) > Email.indexof (' @ ') +1) {k++; }         //you cannot immediately follow the "@" before or after you decide.         if(Email.indexof ('. ') < Email.indexof (' @ ')-1 | | email.indexof ('. ') > Email.indexof (' @ ') +1) {k++; }         //6 characters before @         if(Email.indexof (' @ ') > 5) {k++; }                  if(Email.endswith ("com") | | email.endswith ("org") | | email.endswith ("CN") | | Email.endswith ("NET") ) {k++; }         if(k = = 5) {             return true; }         return false; }}

2. Inspection code
Package Homework3;public class Emailtest {public     static void Main (string[] args) {     String str = "[Email protected ]@163.com ";     Checkemail email = new Checkemail ();     Boolean result = Email.isemail (str);     if (result) {     System.out.println ("The mailbox address is legal");     } else {     System.out.println ("Invalid email address");}}}     
3. Running Results

Iii. Summary

This is the first essay I wrote in the blog Park, although there is no technical content, but it is my study efforts to witness.

I Java programming small white One, is currently trying to move towards the direction of the cattle, welcome to the blog Park's small partners to criticize, learn together, grow together.

Verify that the mailbox format is legitimate (Java code implementation)

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.