我下面这段判断只判断了13、14、15、18开头可以,但像145啦,184啦,154啦都有,我想只要判断手机号码的,怎样改,小女子先在这里谢谢了(*^__^*) if IsNumeric(request("call")) and len(request("call"))=11 and left(request("call"),1)="1" and (mid(request("call"),2,1)= "3" or mid(request("call"),2,1)= "5" or mid(request("call"),2,1)= "8" or mid(request("call"),2,1)= "4") then
解决方案 »
- 求TreeView添加/删除节点的完整例子
- 寻找思路
- Datagrid中使用模版列显示RadioButtonList问题?
- 请大家看看我这个有什么毛病.急!!!
- 为什么要点击两次才更改?
- 关于server.transfer的显示问题
- 请教个文件上传问题,急,在线等
- datalist分页问题---footer中分页的数字不见了???
- 众多Request对象有何区别
- 无法向会话状态服务器发出会话状态请求。请确保已启动 ASP.NET State service,并且客户端和服务器端口保持相同。
- zedgraph控件Y轴显示的问题
- Delphi7调用asp.net的webservice,服务端得到的数据位空
function checkShouJi(){
var shouji=document.getElementById("ShouJi").value;
if(shouji==""){ }
else if(isNaN(shouji)){}
else if(shouji.length!=11){}
else{ }
}用正则更好
ID="RegularExpressionValidator1" runat="server" ErrorMessage="请输入正确的手机号码" ControlToValidate="TextBoxPhone"
ValidationExpression="^(\d{3})?13[0-9]\d{8}|15[0123589]\d{8}|18[79]\d{8}"></asp:RegularExpressionValidator>
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){
alert("不是完整的11位手机号或者正确的手机号前七位");
document.mobileform.mobile.focus();
return false;
[代码] 执行效果
view sourceprint?
01 Match=[1A ] 02 Capture=[1A ] 03 Groups[0]=[1A ] 04 Captures[0]=[1A ] 05 Groups[1]=[1A] 06 Captures[0]=[1A] 07 Groups[2]=[1] 08 Captures[0]=[1] 09 Groups[3]=[A] 10 Captures[0]=[A] 11 Match=[2B ] 12 Capture=[2B ] 13 Groups[0]=[2B ] 14 Captures[0]=[2B ] 15 Groups[1]=[2B] 16 Captures[0]=[2B] 17 Groups[2]=[2] 18 Captures[0]=[2] 19 Groups[3]=[B] 20 Captures[0]=[B] 21 ..................此去省略一些结果 22 Match=[16N ] 23 Capture=[16N ] 24 Groups[0]=[16N ] 25 Captures[0]=[16N ] 26 Groups[1]=[16N] 27 Captures[0]=[16N] 28 Groups[2]=[16] 29 Captures[0]=[16] 30 Groups[3]=[N] 31 Captures[0]=[N]
[代码] 另外一种写法
view sourceprint?
01 /// <summary> 02 /// 使用Regex类的Matches方法所有所有的匹配 03 /// </summary> 04 public void Matches() 05 { 06 //要匹配的字符串 07 string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080"; 08 //正则表达式 09 string pattern = @"((\d+)([a-z]))\s+"; 10 //使用RegexOptions.IgnoreCase枚举值表示不区分大小写 11 Regex r = new Regex(pattern, RegexOptions.IgnoreCase); 12 //使用正则表达式匹配字符串,返回所有的匹配结果 13 MatchCollection matchCollection = r.Matches(text); 14 foreach (Match m in matchCollection) 15 { 16 //显示匹配开始处的索引值和匹配到的值 17 System.Console.WriteLine("Match=[" + m + "]"); 18 CaptureCollection cc = m.Captures; 19 foreach (Capture c in cc) 20 { 21 Console.WriteLine("\tCapture=[" + c + "]"); 22 } 23 for (int i = 0; i < m.Groups.Count; i++) 24 { 25 Group group = m.Groups[i]; 26 System.Console.WriteLine("\t\tGroups[{0}]=[{1}]", i, group); 27 for (int j = 0; j < group.Captures.Count; j++) 28 { 29 Capture capture = group.Captures[j]; 30 Console.WriteLine("\t\t\tCaptures[{0}]=[{1}]", j, capture); 31 } 32 } 33 } 34 }
[代码] 输出结果
view sourceprint?01 Match=[5M ] 02 Capture=[5M ] 03 Groups[0]=[5M ] 04 Captures[0]=[5M ] 05 Groups[1]=[5M] 06 Captures[0]=[5M] 07 Groups[2]=[5] 08 Captures[0]=[5] 09 Groups[3]=[M] 10 Captures[0]=[M] 11 Match=[16N ] 12 Capture=[16N ] 13 Groups[0]=[16N ] 14 Captures[0]=[16N ] 15 Groups[1]=[16N] 16 Captures[0]=[16N] 17 Groups[2]=[16] 18 Captures[0]=[16] 19 Groups[3]=[N] 20 Captures[0]=[N]
ValidationExpression="^1((4[47])|(5[0-35-9])|(8[256789])|(3\d))\d{8}$" ControlToValidate="txtMobile"></asp:RegularExpressionValidator>(其中号段有:
中国移动G网 134 135 136 137 138 139 144 147 150 151 152 157 158 159 187 188
中国联通G网 130 131 132 155 156 185 186
中国电信C网 133 153 180 189
)
这是我收集到的有关的手机号体段总结出来的验证表达式