To determine the amount of input is the correct amount of methods there are two, one is a regular expression, the other is a TextField proxy method
Sometimes it is inevitable to encounter such a demand, does not conform to the rules of the amount of input, it is more reasonable to use this method
If you set the input keyboard to decimal pad, enter a number and a decimal point; if you set the keyboard to number pad, enter as a pure digit
In the case of the above, it is necessary to determine whether the input is reasonable input, such as in the code
Copy Code code as follows:
(Single >= ' 0 ' && single<= ' 9 ') | | single== '. '
If it's just an input number or a decimal point, then you can remove the criterion.
The following limit input amount is very dead:
1. Require users to enter the first point can not be decimal;
2. No more than two digits after the decimal point, unable to enter more than one decimal point;
3. If the first is 0, only the decimal point can be entered later
4. Input amount not exceeding 11 digits
This input first cannot be 0 o'clock and can be in the first place and cannot be "." Place Plus, can be modified according to your own needs.
if (single = = '. ') {
[Textfield.text stringbyreplacingcharactersinrange:range withstring:@ "];
return NO;
}
But this amount can enter 0.00 or so, the input needs to be in the case of the request data to judge empty and enter the minimum amount allowed, do not meet when return;
The restrictions are as follows:
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) String {if (TextField.text.length >) {return range.location <} else{BOOL Ishavedian = YES; if ([Textfield.text rangeofstring:@ "."]. Location==nsnotfound) {Ishavedian=no} if ([string length]>) {Unichar single=[string characteratindex:];//the currently entered character I F (Single >= ' && single<= ') | | single== '. ') The data format is correct {//The first letter cannot be a decimal point if ([Textfield.text length]==) {if (single = =)
{[Textfield.text stringbyreplacingcharactersinrange:range withstring:@ "]; return NO;} } if ([Textfield.text length]== && [Textfield.text isequaltostring:@ "]) {if (single!= '. ')
{[Textfield.text stringbyreplacingcharactersinrange:range withstring:@ "]; return NO;}
if (single== '. ') {if (!ishavedian)//text does not yet have a decimal point {ishavedian=yes; return YES}
else {[Textfield.text stringbyreplacingcharactersinrange:range withstring:@ ']; return NO;}} else {if (Ishavedian)//There is a decimal point {//Determine the number of digits of the decimal point nsrange ran=[textfield.text rangeofstring:@ "."];
Nsinteger tt=range.location-ran.location; if (TT <=) {return YES;}
else{return NO;}
else {return YES}}
}else{//entered data incorrectly formatted [Textfield.text stringbyreplacingcharactersinrange:range withstring:@ "]; return no;}}
else {return YES}} }
The above is a small set to introduce the above is a small set to introduce the use of Uitextfield Limited input amount is the correct decimal knowledge, I hope to
Help, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!