java类中数据验证.docVIP

  • 1
  • 0
  • 约6.85千字
  • 约 13页
  • 2017-05-04 发布于四川
  • 举报
java类中数据验证

java类中的数据验证(正则表达式) import java.util.regex.Matcher; import java.util.regex.Pattern; public final class RegExpValidator { /** * 验证邮箱 * * @param 待验证的字符串 * @return 如果是符合的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean isEmail(String str) { String regex = ^([\\w-\\.]+)@((; return match(regex, str); } /** * 验证IP地址 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean isIP(String str) { String num = (25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d); String regex = ^ + num + \\. + num + \\. + num + \\. + num + $; return match(regex, str); } /** * 验证网址Url * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsUrl(String str) { String regex = http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%=]*)?; return match(regex, str); } /** * 验证电话号码 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsTelephone(String str) { String regex = ^(; return match(regex, str); } /** * 验证输入密码条件(字符与数据同时出现) * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsPassword(String str) { String regex = [A-Za-z]+[0-9]; return match(regex, str); } /** * 验证输入密码长度 (6-18位) * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsPasswLength(String str) { String regex = ^\\d{6,18}$; return match(regex, str); } /** * 验证输入邮政编号 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsPostalcode(String str) { String regex = ^\\d{6}$; return match(regex, str); } /** * 验证输入手机号码 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsHandset(String str) { String regex = ^[1]+[3,5]+\\d{9}$; return match(regex, str); } /** * 验证输入身份证号 * * @param 待验证的字符串 * @return 如果是符合格式的字符串,返回 btrue /b,否则为 bfalse /b */ public static boolean IsIDcard(String str) { String regex = (^\\d{18}$)|(^\\d{15}$); return match(regex, str); } /** * 验证输入两位小数 * * @param 待验证的字符串 *

文档评论(0)

1亿VIP精品文档

相关文档