Regular rules verify mailboxes and mobile numbers

Source: Internet
Author: User

import java.util.regex.matcher;import java.util.regex.pattern;public class  checkmobileandemail { /**  *   *  Verify that the email address is correct   *    *  @param  email  *   *  @return   */ public  Static boolean checkemail (String email)  {  boolean flag = false;   try {   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);    flag = matcher.matches ();   } catch  (Exception e)  {   flag = false;  }   return flag; } /**  *   *  Verify your phone number   *    *  @param  mobiles  *   *  @return  [0-9]{5,9}  */  Public static boolean ismobileno (string mobiles)  {  boolean flag  = false;  try {   pattern p = pattern      .compile ("^ (13[0-9) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ ");    matcher m = p.matcher (mobiles);   flag =  M.matches ();  } catch  (exception e)  {   flag = false;   }  return flag; } public static boolean isnum (String  Number)  {  boolean flag = false;  try {   pattern  p = pattern.compile ("^[0-9]{5}$");    matcher m = p.matcher ( number);    flag = m.matches ();   } catch  (exception e)  {   flag = false;  }  return  flag; } }

This article from "Small book" blog, declined reprint!

Regular rules verify mailboxes and mobile numbers

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.