-1

我可以从 Web 应用程序本身过滤数据,但没有办法从根目录处理这个问题吗?

例如,过滤电话号码:+(12)345 678 91 /011

通过 Web 应用程序使用正则表达式,我目前正在这样做:

bool validPhoneNumber = Common.IsValidTelephoneNumber(this.PhoneNumber);

//Insert Regular Expression
Regex regex = new Regex(@"^((\((\+|00){3}\)|(\()?\d{3}()?|)\d{10})$")

string number = this.PhoneNumber;

// Replace unwanted Characters
number.Replace(" ", "");
number.Replace("-", "");
number.Replace("(", "");
number.Replace(")", "");
number.Replace(":", "");

Match match  = regex.Match(number);

PhoneNumber (Contact)
char[] phonenumber = this.phoneNumber.ToCharArray();
StringBuilder builder = new StringBuilder(10);
for (int i = 0; i < phonenumber.Length; i++)
{
    if (phonenumber[i] >= '0' && phonenumber[i] <= '9')
    {
        builder.Append(phonenumber[i]);
    }
}
phoneNumber = builder.ToString().Substring(0, Math.Min(10, builder.Length));

//OUTPUT: +1234567891

我想做的是收集数据然后更新它;

using (test.Database.OleDB db = new OleDB(OleDBConn)) { 
    db.Sql = 
        "UPDATE [Contact] SET ([MobileNumber]) VALUES " + "(@mobileNumber)" +
        "WHERE [Contact_ID] = @contactId";

    db.SetSqlParam("mobileNumber", MobileNumber);

    db.Handle.ExecuteNonQuery(); // Update the Record 
}
4

1 回答 1

0

我得出的结论是,没有办法更早地编辑数据:

bool validPhoneNumber = Common.IsValidTelephoneNumber(this.PhoneNumber);

//Insert Regular Expression
Regex regex = new Regex(@"^((\((\+|00){3}\)|(\()?\d{3}()?|)\d{10})$")

string number = this.PhoneNumber;

// Replace unwanted Characters
number.Replace(" ", "");
number.Replace("-", "");
number.Replace("(", "");
number.Replace(")", "");
number.Replace(":", "");

Match match  = regex.Match(number);

PhoneNumber (Contact)
char[] phonenumber = this.phoneNumber.ToCharArray();
StringBuilder builder = new StringBuilder(10);
for (int i = 0; i < phonenumber.Length; i++)
{
    if (phonenumber[i] >= '0' && phonenumber[i] <= '9')
    {
        builder.Append(phonenumber[i]);
    }
}
phoneNumber = builder.ToString().Substring(0, Math.Min(10, builder.Length));

所以我决定手动更改数据。

于 2012-11-29T15:52:15.223 回答