zoukankan
html css js c++ java
今天下午写两个函数,还是比较通用的~~~
/**/
///
<summary>
///
产生由英文和数字组成的指定个数的随机数
///
</summary>
///
<param name="number">
产生随机数的个数
</param>
///
<returns>
指定个数的随机英数字符串
</returns>
public
static
string
GetRandomCode(
int
number)
{
string
[] arrList
=
new
string
[]
{
"
0
"
,
"
1
"
,
"
2
"
,
"
3
"
,
"
4
"
,
"
5
"
,
"
6
"
,
"
7
"
,
"
8
"
,
"
9
"
,
"
A
"
,
"
B
"
,
"
C
"
,
"
D
"
,
"
E
"
,
"
F
"
,
"
G
"
,
"
H
"
,
"
I
"
,
"
J
"
,
"
K
"
,
"
L
"
,
"
M
"
,
"
N
"
,
"
O
"
,
"
P
"
,
"
Q
"
,
"
R
"
,
"
S
"
,
"
T
"
,
"
U
"
,
"
W
"
,
"
X
"
,
"
Y
"
,
"
Z
"
}
;
StringBuilder sb
=
new
StringBuilder(
""
) ;
Random random
=
new
Random() ;
for
(
int
i
=
0
; i
<
number ; i
++
)
{
sb.Append(arrList[(
int
)random.Next(
0
,arrList.Length)]) ;
}
return
sb.ToString() ;
}
/**/
///
<summary>
///
判断号码是联通,移动,电信中的哪个,在使用本方法前,请先验证号码的合法性
///
规则:前三位为130-133 联通 ;前三位为135-139或前四位为1340-1348 移动; 其它的应该为电信
///
</summary>
///
<param name="mobile">
要判断的号码
</param>
///
<returns>
返回相应类型:1代表联通;2代表移动;3代表电信
</returns>
public
static
int
GetMobileType(
string
mobile)
{
string
[] chinaUnicom
=
new
string
[]
{
"
130
"
,
"
131
"
,
"
132
"
,
"
133
"
}
;
string
[] chinaMobile1
=
new
string
[]
{
"
135
"
,
"
136
"
,
"
137
"
,
"
138
"
,
"
139
"
}
;
string
[] chinaMobile2
=
new
string
[]
{
"
1340
"
,
"
1341
"
,
"
1342
"
,
"
1343
"
,
"
1344
"
,
"
1345
"
,
"
1346
"
,
"
1347
"
,
"
1348
"
}
;
bool
bolChinaUnicom
=
(Array.IndexOf(chinaUnicom,mobile.Substring(
0
,
3
))
>=
0
) ;
bool
bolChinaMobile1
=
(Array.IndexOf(chinaMobile1,mobile.Substring(
0
,
3
))
>=
0
) ;
bool
bolChinaMobile2
=
(Array.IndexOf(chinaMobile2,mobile.Substring(
0
,
4
))
>=
0
) ;
if
(bolChinaUnicom)
return
1
;
//
联通
if
( bolChinaMobile1
||
bolChinaMobile2 )
return
2
;
//
移动
return
3
;
//
其他为电信
}
注:有朋友建议,第二方法用正则表达式实现更好,确实不错,下面把第二方法的新实现贴上:
/**/
///
<summary>
///
判断号码是联通,移动,电信中的哪个,在使用本方法前,请先验证号码的合法性
///
规则:前三位为130-133 联通 ;前三位为135-139或前四位为1340-1348 移动; 其它的应该为电信
///
</summary>
///
<param name="mobile">
要判断的号码
</param>
///
<returns>
返回相应类型:1代表联通;2代表移动;3代表电信
</returns>
public
static
int
GetMobileType(
string
mobile)
{
if
(IsChinaUnicomNumber(mobile))
return
1
;
if
(IsChinaMobileNumber(mobile))
return
2
;
return
3
;
}
//
是否是联通的号码 测试通过
private
static
bool
IsChinaUnicomNumber(
string
mobile)
{
string
sPattern
=
"
^(130|131|132|133)[0-9]{8}
"
;
bool
isChinaUnicom
=
Regex.IsMatch(mobile,sPattern) ;
return
isChinaUnicom ;
}
//
是否是移动的号码 测试通过
private
static
bool
IsChinaMobileNumber(
string
mobile)
{
string
sPattern
=
"
^(135|136|137|138|139|1340|1341|1342|1343|1344|1345|1346|1347|1348)[1-9]{7,8}
"
;
return
Regex.IsMatch(mobile,sPattern) ;
}
查看全文
相关阅读:
HTML5简介
PHP
纯CSS3写的10个不同的酷炫图片遮罩层效果
零基础如何自学MySQL数据库?
js与jQuery
MAC下GitHub命令操作
框架基础:ajax设计方案(二)---集成轮询技术
框架基础:ajax设计方案(一)---集成核心请求
框架基础:ajax设计方案(三)---集成ajax上传技术
Jquery操作下拉列表和复选框,自定义下拉
原文地址:https://www.cnblogs.com/kwklover/p/83081.html
最新文章
easyui datagrid 列显示和隐藏
Oracle用户信息查询
python 两个经纬度点之间的距离
python之 判断点是否在多边形范围内
mysql数据库操作以及excel修改
Python 装饰器的理解与示例
微信JS接口
SEO外链和反链到底有什么区别?
常用的前端调试工具
SEO搜索引擎优化的实施方案
热门文章
如何让你的网站排名靠前
js中调用函数时加不加括号的问题
js实现瀑布流以及加载效果
Javascript中最常用的55个经典技巧
【Ionic+AngularJS 开发】之『个人日常管理』App(二)
【Ionic+AngularJS 开发】之『个人日常管理』App(一)
关于Ajax工作原理
js实现倒计时及时间对象
深入理解JavaScript系列(1):编写高质量JavaScript代码的基本要点
css平行四边形与菱形变换
Copyright © 2011-2022 走看看