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

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -