Reputation: 3294
i have project in ASP.NET MVC 3 and a mysql database that contains a table of string values for phone numbers (this phone numbers can be stored as 123 456-789 or 12345 6789 or 123456789 or any ways the user enter his number) and other table with a keywords data for that users. The thing is that i have a search that will find in the keywords table (fulltext table) for the users, but i'm writing a method that search in the phone table if the search query matches against certain regular expression. I have 2 questions: - How could be that regular expression from the C# code side that tells what method to execute (SearchByKeyword or SearchByNumber)? - Using the same regular expression i think, i must do the mysql query to search in the phones table... how can i do it?
I hope i have explained well and sorry if my english is a little bit bad.
Upvotes: 0
Views: 229
Reputation: 3414
I would say that its bad idea to feed a phone number from the input -> directly to query variable.
better way would be:
input -> parser, error check procedure -> MySQL query request.
and before adding your phone number to the query - you can remove all extra symbols, like (, ), -, "space", etc.
Upvotes: 1
Reputation: 61725
It's best when you capture the data to standardise the format it is saved in, IE:
111-111-1-111-11
1111-1111-1111
111111111111
1-1-1-1-1-1-1-1-1-1-1-1
All will save as
111111111111
You can then do a simple LIKE query:
SELECT * FROM tblNumbers WHERE number LIKE '%111%'
Upvotes: 1