-1

I can filter data from the Web-Application itself, but isn't there a way to handle this from the root?

For Example, filtering a telephone number: +(12)345 678 91 /011

With a Regular Expression through the Web-Application, which I am currently doing:

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

What I would like to do is Collect Data and then Update it;

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 
}
Rafael
  • 715
  • 1
  • 16
  • 34
  • 1
    What do you mean by "handle this from the root"? – J0HN Nov 27 '12 at 13:16
  • Update the database (output) not the output from the database. – Rafael Nov 27 '12 at 13:25
  • So, your first approach was to save the phone into the database as user provided and then sanitize the output from the DB, and now you want to sanitize and format the input before saving to the database, right? – J0HN Nov 27 '12 at 13:34
  • Yes, first it was handled by the Regular Expression, when the data was retreived. now I want to Update it a step back. – Rafael Nov 27 '12 at 19:22

1 Answers1

0

I have came to the conclusion there is no way to edit the data earlier than:

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));

So I decided to change the data manually.

Rafael
  • 715
  • 1
  • 16
  • 34