locked
hardcode list validation in MVC RRS feed

  • Question

  • Hello guys,

     

    I am developing asp.net mvc application...in one of the form i have field State which shold be validated server side....

    state should only state values from given list, It should be two character and from list. Hardcode list that is 'AA', 'AB' and so on..

    I have taken txtbox for the field of State...now how do i validate the entered value with hardcode list???

     

    please help me how do i do that?

    • Moved by SamAgain Wednesday, September 8, 2010 8:44 AM (From:.NET Base Class Library)
    Friday, September 3, 2010 9:06 AM

Answers

  • Microsoft maintains a separate forum system for ASP.NET questions, this should be asked there: http://forums.asp.net

    I'll answer it in a non-ASP.NET specific way.  For help integrating with ASP.NET, you'll need to ask on the other forums.

    BTW, even with this answer it is more of a C# answer than a BCL answer:

    public static bool IsValidState(string s)
    {
    	switch (s)
    	{
    		case "CA":
    		case "NY":
    		case "TX":
    		/* etc.. */
    			return true;
    		default:
    			return false;
    	}
    }
    

     

    • Proposed as answer by Just Karl Tuesday, January 14, 2014 11:03 PM
    • Marked as answer by Just Karl Tuesday, January 14, 2014 11:03 PM
    Friday, September 3, 2010 5:45 PM

All replies

  • Microsoft maintains a separate forum system for ASP.NET questions, this should be asked there: http://forums.asp.net

    I'll answer it in a non-ASP.NET specific way.  For help integrating with ASP.NET, you'll need to ask on the other forums.

    BTW, even with this answer it is more of a C# answer than a BCL answer:

    public static bool IsValidState(string s)
    {
    	switch (s)
    	{
    		case "CA":
    		case "NY":
    		case "TX":
    		/* etc.. */
    			return true;
    		default:
    			return false;
    	}
    }
    

     

    • Proposed as answer by Just Karl Tuesday, January 14, 2014 11:03 PM
    • Marked as answer by Just Karl Tuesday, January 14, 2014 11:03 PM
    Friday, September 3, 2010 5:45 PM
  • sorry for putting question at wrong place..
    Monday, September 6, 2010 12:32 PM