Verification rules :(real-time verification)
- Do not start or end with any character
- We start with the decimal point, plus the decimal point
0
Fill a[.26 -> 0.26]
0
No numbers or symbols may be added after the decimal point- You cannot enter more than one decimal point
- Up to two decimal places
- for
0
0.0
0.00
The judgment of the - Auto fill with less than two decimal points after out-of-focus or submission
0
[0.2 -> 0.20]
onNumChange = e => { const num = e.target.value; console.log(num); if (! /^[\d\.]*$/.test(num)) return; State if (num[0] === '.') return; State if (num[0] === '0') {// If (num[1] && num[1]! == '.') return; State} if (num.split(" ").filter(s => s === '.').length > 1) return; State if (num.split('.')[1].length > 2) {// if (num.split('.')[1].length > 2) return; State} if (! /\d+\.$/.test(num)) {this.setState({isDisabled: true // isDisabled); } the if (num = = = '0' | | num = = = '0.0' | | num = = = '0.00') {enclosing setState ({isDisabled: true / / isDisabled button is disabled}); } this. SetState ({numVal: num}, () = > {/ / callback interface real-time}); } inputBlur = () => { let num = this.state.numVal; If (num. Includes (')) {/ / there are decimal let [num1, num2] = num. Split ('. '); num2 = num2.padEnd(2, '0'); Num = '${num1}.${num2}'; } else {// integer num += '.00'; } this.setState({ numVal: num }); }Copy the code
To modify the
PatternType: {/ / 'positive' positive type: ^ 1-9] [\ d * \ \ d * \ | 0. \ [1-9] \ d d * * | \ [1-9] d * $/ / / up to two decimal places' is2Decimal ': / ^ \ d + \.? \d{0,2}$/ // up to six decimal places 'is6Decimal': /^\d+\.? Metab \ d {0} $/ 'isMobileNumber' : /^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\d{8}|1(3[4-9]|4[7]|5[0-27-9]|7[08]|8[2-478])\d{8}|1(3[0-2]|4[5]|5[56]|7[01 56]|8[56])\d{8}|1(3[3]|4[9]|53|7[037]|8[019])\d{8}$/, 'isMail': /^[a-zA-Z0-9]+([._\\-]*[a-zA-Z0-9])*@([a-zA-Z0-9]+[-a-zA-Z0-9]*[a-zA-Z0-9]+.) Tobacco on {1} [a zA - Z0-9] + $/ 'isMailRational' : / ^ \ w + (1 [-]? \w+)*@\w+([.-]? (\. \ \ w +) * w} {2 and 5) + $/ 'isSpecialChar' : '[` ~! @ # $^ & * () = | {} \' :; \ ', \ \ [\ \] < > /? ~! @ # $... & * () - | {} 【 】 '; : "" \ '.,,? '// positiveRational': /^-? [1-9]\d*\.\d*|-? 0\.\d*[1-9]\d*|-? [1-9]\d*$/ // at most two decimal digits 'is2DecimalRational': /^-? \d+\.? \d{0,2}$/ // up to three decimal places 'is3Decimal': /^\d+\.? \d{0,3}$/ // up to ten decimal places 'is10Decimal': /^\d+\.? \ d {0, 10} $/ 'isSpecialCharFP' : / / < > / / 'isPositive' : / ^ \ [1-9] d * $/ / / password 'isOldPwd' : / (^) (\ w) 6, 20} {$| (^ (? ! ([0-9] + $)? ! [a zA - Z] + $) [0-9 a zA - Z] 6, 20} {$) /, 'isPwd: / ^ (? ! ([0-9] + $)? ! [a zA - Z] + $) [0-9 a zA - Z] 6, 20} {$/,},Copy the code