c# - Decimal Point in Windows phone textfield -
hello fellow c# , windows phone developers,
for windows phone application, have textfield requiring user enter age. during debugging mode entered number .8. , clicked proceed , application unexpectedly closed. code need add can post message box informing user numbers more 1 decimal point unacceptable. please
assuming input string, try:
if (input.indexof('.') == -1 || input.lastindexof('.') == input.indexof('.')) { //good } else messagebox.show("more 1 decimal point");
a better way though use tryparse check number formatting
float age; if (float.tryparse(input, out age)) { //good } else messagebox.show("invalid age.");
Comments
Post a Comment