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)