IOS TextField Enter the amount of the limit, 9 digits before the decimal point, two digits later, if no decimal point, the maximum number of digits is 9 bits, plus the decimal point, the maximum number of digits is 12 bits, the maximum number of digits can be deleted
-(BOOL) TextField: (uitextfield *) TextField shouldchangecharactersinrange: (nsrange) range Replacementstring: (nsstring *) string {
//Decide whether to enter the content, or the user clicked the Keyboard delete button
If (![ String isequaltostring:@ ""]) {
nscharacterset *cs;
if ([TextField isequal:counttextfield]) {
//The position of the decimal point in the string the first number starts at the 0 position
nsinteger dotlocation = [TextField. Text rangeofstring:@ "." ]. Location ;
//Determine if there are any decimal points in the string, and it is not the first digit
//Nsnotfound indicates that a request operation is something or item is not found, or does not exist
//Range.location represents the position of the current input in the entire string, where the position number starts at 0
if (dotlocation = = nsnotfound && range. Location! = 0) {
//Fetch contains only the content contained in "Mydotnumbers" and the remainder is removed
/*
The function of [Nscharacterset charactersetwithcharactersinstring:mydotnumbers] is to remove everything contained in the "Mydotnumbers" as long as the contents of the string contain the " Mydotnumbers "Part of the content will be abandoned
Adding Invertedset at the end of the above method will reverse the action, taking only the same characters as the contents of "Mydotnumbers"
*/
CS = [[nscharacterset charactersetwithcharactersinstring:numberswithdot] invertedset ];
if (range. Location >= 9) {
NSLog(@ "The amount of a single sum cannot exceed billion");
if ([string isequaltostring:@ ".") ] && range. Location = = 9) {
return YES;
}
return NO;
}
}Else {
CS = [[nscharacterset charactersetwithcharactersinstring:numberswithoutdot] Invertedset];
}
separate arrays by CS, array by @ "" to isolate strings
nsstring *filtered = [[String Componentsseparatedbycharactersinset: cs] componentsjoinedbystring :@""];
BOOL basictest = [string isequaltostring: filtered];
if (!basictest) {
NSLog(@ "Only enter numbers and decimal points");
return NO;
}
if (dotlocation ! = Nsnotfound && range. Location > dotlocation + 2) {
NSLog(@ "up to two digits after the decimal point");
return NO;
}
if (TextField. Text. Length > one) {
return NO;
}
}
}
return YES;
}
IOS TextField limit of input amount, 9 digits before decimal point, two digits behind