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.