Reputation: 1060
I am having these two table's
Country Table Details Table
Id CountryId CountryName Id CountryId Description
-------------------------- ---------------------------
1 1 UK 1 1 xxxxx
2 2 USA 2 2 YYYYY
Design Page
i will collect country name and description and save details to database
My Problem
if user give the country name as United Kingdom
and give description and click save..
@the time i my database i will use it as UK
But user enter as United Kingdom
occurs mismatch
if User enter as full formed country_name how to i identify the short form of that particular country.
For example:if user enter United Kingdom convert to UK
How do i will check it..is there any online website to do this?
Please Say any Idea.
~Thanks.
Upvotes: 2
Views: 286
Reputation: 362
@Max is right! @GOPI if you want this way, use a Dictionary class to map user input. Use Hashtable in Dictionary class for auto suggestion and easy implementation. And also notify user about wrong inpur(in case if user inputs United Kingkong insted of United Kingdom).
Upvotes: 0
Reputation: 2931
You can use http://www.dotnetperls.com/substring
// Get first two characters
string sub = input.Substring(0, 2);
Upvotes: 0
Reputation: 540
If you want to do it via a textbox but still make sure the country code is selected I suggest you use one of jQuery's AutoComplete features. I suggest you have a look at Select2
Check out section Basics. It does exactly what you need it for (it even has example for country codes).
Upvotes: 1
Reputation: 17964
Something like this:
select ct.CountryName from Country.Table ct
inner join Country.Details cd on ct.CountryId = cd.CountryId
where cd.Description = 'United Kingdom'
Upvotes: 0
Reputation: 7416
As @Max suggest it, you should use a ComboBox to force the user to choose a "good" option.
However, if you really need a text box, you should use anopther column in your Country
table called CountryShortForm
for example. Strore in this colum the short form of the country, like UK
for United Kingdom
.
Then, when you save your data, just take a look if what is entered correspond to the CountryName
or the CountryShortForm
.
But attention, nothing prevent the users to enter ENG
or U-K
for exemple, so be really careful with TextBoxes... which are definitively not the good choice here !
Upvotes: 0