Java uses regular expressions to determine whether a mailbox format is correct _java

Source: Internet
Author: User
Tags alphabetic character regular expression string format

The example in this article describes how Java uses regular expressions to determine whether a mailbox format is correct. Share to everyone for your reference. as follows:

Import java.io.*; public class Checkemail {public static Boolean checkemail (string email) {//Verify mailbox's regular expression string format = ' \\p{alph a}\\w{2,15}[@][a-z0-9]{3,}[.]
   \\p{lower}{2,} "; P{alpha}: Content is required, and alphabetic character [\p{lower}\p{upper}] is equivalent.
   For example: 200896@163.com is not legal. w{2,15}: 2~15 [a-za-z_0-9] character; w{} content is required.
   For example: dyh@152.com is legal.
   [A-z0-9]{3,}: At least three [a-z0-9] characters, [] are required, such as: dyh200896@16.com is illegal. //[.]:'.'
   , such as: dyh200896@163com is illegal. p{lower}{2,} lowercase letters, more than two.
   For example: DYH200896@163.C is not legal. if (email.matches (format)) {return true;//mailbox name is valid, returns true} else {return false;//mailbox name is not valid, back to Fals
   e}} public static void Main (string[] args) throws Exception {String email = "cc**365@163.com";//mailbox to be validated
   while (true) {email = new BufferedReader (new InputStreamReader (system.in)). ReadLine (); if (checkemail.checkemail (email))//Verify that the mailbox {System.out.println (email+) is a valid mailbox name.
   "); } else {System.out.println (email+) is not a valid mailbox name.
   "); }
  }
 }
}

 

PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:

JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript

Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg

I hope this article will help you with your Java programming.

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.