输入框校验:只能输入中文
//js文件
validate: function() {
var reg = /^[\u4e00-\u9fa5]+$/;
if(reg.test(this.coupletUp)&®.test(this.coupletDown))
{
this.error=false;
this.errorText="";
this.isdisabled=false;
return true;
}
this.error=true;
this.errorText="请输入汉字";
this.isdisabled=true;
return false;
},
/**
* 上传编辑后春联内容
*/
coupletConfirm() {
const status = this.validate()
if (status) {
this.renderData.springScrolls.L = this.coupletUp;
this.renderData.springScrolls.R = this.coupletDown;
this.inputImageModal=false;
}
},
<!--wxml文件-->
<div class="couplet-up">
<div class="couplet-label">上联:</div>
<div class="couplet-content"><input class="couplet-text" placeholder="最多输入七个字" maxlength="7" v-model="coupletUp" @blur="validate"></div>
</div>
<div class="couplet-down">
<div class="couplet-label">下联:</div>
<div class="couplet-content"><input class="couplet-text" placeholder="最多输入七个字" maxlength="7" v-model="coupletDown" @blur="validate"></div>
</div>
<div class="error_tip">
<span v-if="error">{{errorText}}</span>
</div>
<button class="couplet-confirm" :class="isdisabled?btndisabled:''" @tap="coupletConfirm" :disabled="isdisabled">确定</button>