textarea的值转换为JavaScript数组(以换行分隔)验证长度及重复内容 去除空格

textarea的值转换为JavaScript数组(以换行分隔) 验证长度及重复内容 去除空格
<el-input
  type="textarea"
  :rows="3"
  placeholder="请输入公司序列号"
  v-model="ruleForm.CompanySerial">
</el-input>
 
let lines=this.ruleForm.CompanySerial.split(/ /);
for (var i=0; i < lines.sort().length; i++) {
  if (/S/.test(lines[i])) {
    if($.trim(lines[i]).length>=50){
    this.$message({
      message: `每条长度不可大于50个字符,错误内容为:${lines[i]}`,
      type: 'error'
    })
    return false 
  }else{
    this.falgLenght=true;
  }
  if($.trim(lines[i])==$.trim(lines[i+1])){
    this.$message({
      message: `序列号有重复内容不可提交,重复内容:${lines[i]}`,
      type: 'error'
    });
  
  this.ruleForm.CompanySerialList=[];
  return false
  }else{
    //定义数组 push到数组中
    this.ruleForm.CompanySerialList.push($.trim(lines[i]));
    this.falg=true;
  }
  }
}
if(this.falg && this.falgLenght){
  alert('成立')  
}
原文地址:https://www.cnblogs.com/wgy0528/p/11199576.html