如何禁止在编辑文本中输入零后的数字?
我仅对此进行了验证..
if (TextUtils.isEmpty(strBalance)) {
Toast.makeText(TransactionSellINActivity.this, "Amount should not be empty", Toast.LENGTH_SHORT)
.show();
} else if (strBalance.equalsIgnoreCase("0")) {
Toast.makeText(TransactionSellINActivity.this, "Amount should not be Zero", Toast.LENGTH_SHORT)
.show();
}
但是如果用户输入 01 或 001 或 02,03 等,?即零后的数字? -> 我想限制这些数字
遇到这种情况该如何处理?
最佳答案
if (TextUtils.isEmpty(strBalance)) {
Toast.makeText(TransactionSellINActivity.this, "Amount should not be empty", Toast.LENGTH_SHORT)
.show();
} else if (strBalance.equalsIgnoreCase("0")) {
Toast.makeText(TransactionSellINActivity.this, "Amount should not be Zero", Toast.LENGTH_SHORT)
.show();
}
else if(strBalance.indexOf("0")!=a.length()-1)
{
Toast.makeText(TransactionSellINActivity.this, "Amount Not Valid", Toast.LENGTH_SHORT)
.show();
}
else{
Toast.makeText(TransactionSellINActivity.this, "Amount Valid", Toast.LENGTH_SHORT)
.show();
}
关于java - 如何禁止在编辑文本中输入零后的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48657972/