1, the legality of IP addresses
export function validateIP(rule, value,callback) { if(value==''||value==undefined||value==null){ callback(); }else { const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; if ((!reg.test(value)) && value != '') { callback(new Error('请输入正确的IP地址')); } else { callback(); } } }
2 whether fixed-line or mobile phone number.
validatePhoneTwo function Export (rule, value, the callback) { const REG = / ^ ((0 \ D {2,3} - \ D {7, 8}) | (. 1 [34578] \. 9 {D})) $ / ;; IF (value == '' || || value == undefined value == null) { the callback (); } {the else IF (!! (reg.test (value)) && value = '') { the callback (new Error ( 'Please enter a valid phone number or fixed number')); } {the else the callback (); } } }
3. whether the phone number
export function validatePhone(rule, value,callback) { const reg =/^[1][3-9][0-9]{9}$/; if(value==''||value==undefined||value==null){ callback(); }else { if ((!reg.test(value)) && value != '') { callback(new Error('请输入正确的电话号码')); } else { callback(); } } }
4. Is the ID number
Export function validateIdNo (rule, value, the callback) { const REG = / (^ \ D {15} $) | (^ \ D {18 is} $) | (^ \ D {. 17} (\ D | X-| X) $) /; IF (value == '' || || value == undefined value == null) { the callback (); } the else { ! IF ((reg.test (value)) = value &&! '') { the callback (new new Error ( 'Please enter the correct ID number')); } {the else the callback (); } } }
The check value range
checkMax20000 function Export (rule, value, the callback) { IF (value == '' || || value == undefined value == null) { the callback (); } {the else IF (Number The (value)!) the callback (new new Error ( "Please enter a number between [1,20000] ')); } the else IF (value <value. 1 ||> 20000) { the callback (new new Error (" Please enter a number between [1,20000]' )); } {the else the callback (); } }
6. Verify maximum value input box
checkMaxVal function Export (rule, value, the callback) { IF (value <0 || value> maximum value) { the callback (new new Error ( 'Enter [0, max] number between')); } {the else the callback (); } }
7. Verify integer
Export function isInteger (rule, value, the callback) { IF (! value) { return the callback (new new Error ( 'input may not be empty')); } the setTimeout (() => { ! IF (Number The (value)) { the callback (new Error ( 'Please enter a positive integer')); } the else { const = Re / ^ [0-9] * [1-9] [0-9] * $ /; const rsCheck re.test = (value) ; IF (! rsCheck) { the callback (new new Error ( 'Please enter a positive integer')); } {the else the callback (); } } }, 0); }
8. Verify two decimal places
validateValidity = const (rule, value, the callback) => { IF (! / (^ [1-9] ([0-9] +)? (\. [0-9] {1,2})? $) | (^ (0) {} $. 1) |. (.? ^ [0-9] \ [0-9] ([0-9]) $) / Test (value)) { the callback (new new Error ( ' up to two decimal places !!! ')); } {the else the callback (); } };
Usage: import directly incorporated the use of local, then added to the checksum in the rules.
Follow-up will add.