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
Post a Comment