console
let a = document.querySelector('.input')
a.addEventListener('input', b)
function b() {
let str = a.value
let user = new User(str);
console.log(user.getOrderId(), user.getPayment())
}
class User {
constructor(str) {
let arr = str.split('\t')
this.orderId = arr[3]
this.payment = arr[7]
this.accountInfo = this.matchInfo(arr[9])
}
matchInfo(str) {
const nameRegex = /[\u4E00-\u9FFF]{2,4}/;
const emailRegex = /\w+(-+.\w+)*@\w+(-.\w+)*.\w+(-.\w+)*/g;
const accountRegex = /\d{11}/g;
const nameMatch = str.match(nameRegex);
const accountMatch = str.includes('@') ? str.match(emailRegex) : str.match(accountRegex);
const info = {
name: nameMatch[0] || '',
account: accountMatch[0] || ''
};
console.log(info)
return info;
}
getOrderId() {
return this.orderId;
}
getPayment() {
return this.payment;
}
getAccountInfo() {
return this.accountInfo;
}
getUsername() {
return this.accountInfo.name;
}
getAccount() {
return this.accountInfo.account;
}
}
<input class="input" type="text">