android工具类正则表达式,Android开发中超好用的正则表达式工具类RegexUtil完整实例...

本文提供了一个用于验证输入数据格式的Java工具类RegexUtil,包括车牌号、身份证号、编码、固定电话、邮政编码、面积、手机号码和银行账号的正则表达式。此外,还推荐了两款正则表达式在线测试工具,帮助开发者进行正则表达式的测试和调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文实例讲述了android开发中超好用的正则表达式工具类regexutil。分享给大家供大家参考,具体如下:

/***********************************************

* 正则表达式工具

*

* @author chen.lin

* @version 1.0

************************************************/

public class regexutil {

/**

* 车牌号码pattern

*/

public static final pattern plate_number_pattern = pattern

.compile("^[\u0391-\uffe5]{1}[a-za-z0-9]{6}$");

/**

* 证件号码pattern

*/

public static final pattern id_code_pattern = pattern

.compile("^[a-za-z0-9]+$");

/**

* 编码pattern

*/

public static final pattern code_pattern = pattern

.compile("^[a-za-z0-9]+$");

/**

* 固定电话编码pattern

*/

public static final pattern phone_number_pattern = pattern

.compile("0\\d{2,3}-[0-9]+");

/**

* 邮政编码pattern

*/

public static final pattern post_code_pattern = pattern.compile("\\d{6}");

/**

* 面积pattern

*/

public static final pattern area_pattern = pattern.compile("\\d*.?\\d*");

/**

* 手机号码pattern

*/

public static final pattern mobile_number_pattern = pattern

.compile("\\d{11}");

/**

* 银行帐号pattern

*/

public static final pattern account_number_pattern = pattern

.compile("\\d{16,21}");

/**

* 车牌号码是否正确

*

* @param s

* @return

*/

public static boolean isplatenumber(string s) {

matcher m = plate_number_pattern.matcher(s);

return m.matches();

}

/**

* 证件号码是否正确

*

* @param s

* @return

*/

public static boolean isidcode(string s) {

matcher m = id_code_pattern.matcher(s);

return m.matches();

}

/**

* 编码是否正确

*

* @param s

* @return

*/

public static boolean iscode(string s) {

matcher m = code_pattern.matcher(s);

return m.matches();

}

/**

* 固话编码是否正确

*

* @param s

* @return

*/

public static boolean isphonenumber(string s) {

matcher m = phone_number_pattern.matcher(s);

return m.matches();

}

/**

* 邮政编码是否正确

*

* @param s

* @return

*/

public static boolean ispostcode(string s) {

matcher m = post_code_pattern.matcher(s);

return m.matches();

}

/**

* 面积是否正确

*

* @param s

* @return

*/

public static boolean isarea(string s) {

matcher m = area_pattern.matcher(s);

return m.matches();

}

/**

* 手机号码否正确

*

* @param s

* @return

*/

public static boolean ismobilenumber(string s) {

matcher m = mobile_number_pattern.matcher(s);

return m.matches();

}

/**

* 银行账号否正确

*

* @param s

* @return

*/

public static boolean isaccountnumber(string s) {

matcher m = account_number_pattern.matcher(s);

return m.matches();

}

}

ps:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

javascript正则表达式在线测试工具:

正则表达式在线生成工具:

希望本文所述对大家android程序设计有所帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值