asp.net - How can we validate a string variable for numeric format? -


the if condition checking null or empty, wouldn't fix flaw. want check whether year string contains number.

string year = request.params[""year""]; if (year == null || year.equals(""""))     {         year = system.datetime.now.year.tostring();     } 

use tryparse:

int x; if (year == null || year.equals("""") || !int.tryparse(year, out x)){      // code  } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -