//對輸入框的限制 金額限制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([self.InputAmount.text rangeOfString:@"."].location==NSNotFound) {
isHaveDian=NO;
}
if ([string length]>0)
{
unichar single=[string characterAtIndex:0];//當(dāng)前輸入的字符
if ((single >='0' && single<='9') || single=='.')//數(shù)據(jù)格式正確
{
//首字母不能為0和小數(shù)點
if([self.InputAmount.text length]==0){
if(single == '.'){
//[self alertView:@"親腻脏,第一個數(shù)字不能為小數(shù)點"];
[self.InputAmount.text stringByReplacingCharactersInRange:range withString:@""];
return NO;
}
if (single == '0') {
//[self alertView:@"親分瘦,第一個數(shù)字不能為0"];
[self.InputAmount.text stringByReplacingCharactersInRange:range withString:@""];
return NO;
}
}
if (single=='.')
{
if(!isHaveDian)//text中還沒有小數(shù)點
{
isHaveDian=YES;
return YES;
}else
{
//[self alertView:@"親拇砰,您已經(jīng)輸入過小數(shù)點了"];
[self.InputAmount.text stringByReplacingCharactersInRange:range withString:@""];
return NO;
}
}
else
{
if (isHaveDian)//存在小數(shù)點
{
//判斷小數(shù)點的位數(shù)
NSRange ran=[self.InputAmount.text rangeOfString:@"."];
NSInteger tt=range.location-ran.location;
if (tt <= 2){
return YES;
}else{
//[self alertView:@"親,您最多輸入兩位小數(shù)"];
return NO;
}
}
else
{
return YES;
}
}
}else{//輸入的數(shù)據(jù)格式不正確
//[self alertView:@"親匕垫,您輸入的格式不正確"];
[self.InputAmount.text stringByReplacingCharactersInRange:range withString:@""];
return NO;
}
}
else
{
return YES;
}
}