Uni-app mobile phone number and password length verification

First: create a new directory check, and create an index.js file in this directory

const check = {
    
    
	telphone(data) {
    
    
		if(!(/^1[3456789]\d{9}$/.test(data))){
    
    
			uni.showToast({
    
    
			    title: "手机号码不正确",
				icon:'none'
			});     
			return false; 
		} 
		return true
	},
	password(data) {
    
    
		if(data.length<6) {
    
    
			uni.showToast({
    
    
			    title: "密码长度不能小于6位",
				icon:'none'
			});   
			return false;  
		}
		return true
	}
	
}

export default check;

Import the file in main.js and create an instance

import check from './check/index.js'
Vue.prototype.check=check

Use in components

if(this.check.telphone(this.telphone) == false){
    
    return}
if(this.check.password(this.password) == false){
    
    return}

Guess you like

Origin blog.csdn.net/weixin_44640323/article/details/112488732