Java determines whether a mailbox is legitimate

Source: Internet
Author: User
Tags valid email address

public class Test {
public static void Main (string[] args) {

Email
String check = "^ ([a-z0-9a-z]+[-|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+) \ \.) +[a-za-z]{2,}$ ";
Pattern regex = pattern.compile (check);
Matcher Matcher = Regex.matcher ("[email protected]");
Boolean ismatched = Matcher.matches ();
System.out.println (ismatched);
}

public static void Main (string[] args) {
Scanner scanner=new Scanner (system.in);
String Mail=null;
System.out.println ("Please enter e-mail:");
Mail=scanner.next ();
Pattern pattern=pattern.compile ("\\[email protected" (\\w+.) +[a-z]{2,3} ");//\w represents a-z,a-z,0-9 (\ \ Escape character)
Matcher matcher=pattern.matcher (mail);
Boolean b=matcher.matches ();
if (b) {
SYSTEM.OUT.PRINTLN (mail+ "Valid email address! ");
}else {
SYSTEM.OUT.PRINTLN (mail+ "Format Error!! ");
}
}



/**
Verification of legality of *javascript e-mail
*/
function Isemail (email)
{
var srt=/^\w+ ((-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ ((\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/;
if (srt.test (email))
{
When it's not legal
return false;
}
Else
{
Legal time
return true;
}
}
}

public static Boolean validateemail (String email) {
Boolean flag = false;
int pos = Email.indexof ("@");
if (pos = =-1 | | pos = = 0 | | pos = = email.length ()-1) {
return false;
}
String[] strings = Email.split ("@");
if (strings.length! = 2) {//If the mailbox is not in [email protected] Format
return false;
}
Charsequence cs = strings[0];
for (int i = 0; i < cs.length (); i++) {
char C = Cs.charat (i);
if (! Character.isletter (c) &&! Character.isdigit (c)) {
return false;
}
}
pos = Strings[1].indexof ("."); /If there is no after @, then it is the wrong mailbox.
if (pos = =-1 | | pos = = 0 | | pos = = email.length ()-1) {
return false;
}
strings = Strings[1].split (".");
for (int j = 0; J < Strings.length; J + +) {
cs = Strings[j];
if (cs.length () = = 0) {
return false;
}
for (int i = 0; i < cs.length (); i++) {//If an irregular character is protected, it indicates an error
char C = Cs.charat (i);
if (! Character.isletter (c) &&! Character.isdigit (c)) {
return false;
}
}
}
return true;
}

Java determines whether a mailbox is legitimate

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.