电话号码格式 function 如何写
public string formatPhoneNumber(string phoneNumber){
var piece1 = phoneNumber.substring(0, 3); //123
var piece2 = phoneNumber.substring(3, 6); //456
var piece3 = phoneNumber.substring(6); //7890
//should return (123)456-7890
return String.Format("({0})-{1}-{2}", piece1, piece2, piece3);
}
error 有 cannot resolve for symbol substring,
大牛们有没有办法帮忙? --------------------编程问答-------------------- http://topic.csdn.net/t/20040609/13/3076793.html --------------------编程问答-------------------- 用一个正则表达式 就直接做了
private static Regex RegPhone = new Regex("^[0-9]+[-]?[0-9]+[-]?[0-9]$"); --------------------编程问答-------------------- 你这样子截取也不对呀 --------------------编程问答-------------------- var piece2 = phoneNumber.substring(3, 3); //456
return String.Format("({0}){1}-{2}", piece1, piece2, piece3); --------------------编程问答--------------------
楼上正解,楼主误解了
substring(3, 3); //从3开如,取3位 --------------------编程问答-------------------- 加个命名空间using System.Text.RegularExpressions;
//验证手机,这是一个验证1开头的,11位数字组成的号码,现在号码变化快,还是不要限定死了
Label5.Text = "";
Regex rx = new Regex(@"^1\d{10}$");
if (Text3.Value == string.Empty)
{
Label5.Visible = true;
Label5.Text = "手机不能为空.";
}
else if (!rx.IsMatch(Text3.Value))
{
Label5.Visible = true;
Label5.Text = " 请输入正确手机号码.";
}
补充:.NET技术 , ASP.NET