WhiteSpace

Mar 15, 2009 at 10:46 PM
Newbie to database / ASP.NET MVC, so go easy on me.

What is the best way to trim the white space in the Country and PhoneNumber textbox input?  In working through the tutorial, I got stuck implemented/testing the delete feature.  This might have more to do with using country as a Regex key.  Added the code below to fix the problem, however I think it would be better to fix the data going into the database.

if (country != null && countryRegex.ContainsKey(country.Trim()) )
                    {
                        return countryRegex[country.Trim()].IsMatch(phoneNumber.Trim());
                    }

Thanks
Apr 13, 2009 at 6:04 PM
Edited Apr 13, 2009 at 6:10 PM
I would use the trim() as you do above, I might change the if to look for:

string sHolder = country.trim();

if (!String.IsNullOrEmpty(sHolder) && countryRegex.ContainsKey(sHolder)  )
{
         return countryRegex[sHolder].IsMatch(phoneNumber.Trim());

}

You might want to create a method to clean the input this can be called anytime:

 

 

public string CleanText(string inText)

 

{

 

 

return inText.Trim();

 

}

or if you want to clean all whitespaces

public string CleanText(string inText)

 {

 

return inText.Replace(" ", "");

 

 }

 



Hope this helps

 

David........