RegExp & bug
translated bug
// OK && tranlate `/`
let new_obj_reg = new RegExp(`^(([^<>()\\[\\]\\.,;:\\s@\\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$`);
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
new_obj_reg.test(`admin@xgqfrms.xyz`);
// true
// Error && not tranlate `/`
let obj_reg = new RegExp(`^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$`);
// /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2,})$/
obj_reg.test(`admin@xgqfrms.xyz`);
// false
let reg = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/;
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
reg.test(`admin@xgqfrms.xyz`);
// true
// reg.test(`"admin@xgqfrms.xyz"`);
// false
console.log(`reg =\n`, reg);
console.log(`obj_reg =\n`, obj_reg);
console.log(`new_obj_reg =\n`, new_obj_reg);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
var regex1 = /\w+/;
let regex2 = new RegExp('\\w+');
console.log(regex1);
// expected output: /\w+/
console.log(regex2);
// expected output: /\w+/
console.log(regex1 === regex2);
// expected output: false
console.log({} === {});
// false
转译
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Description
// 转译 `\` && OK
let new_obj_reg = new RegExp(`^(([^<>()\\[\\]\\.,;:\\s@\\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$`);
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
new_obj_reg.test(`admin@xgqfrms.xyz`);
// true
// 未转译 `\` && Error
let obj_reg = new RegExp(`^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$`);
// /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2,})$/
obj_reg.test(`admin@xgqfrms.xyz`);
// false
let reg = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/;
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
reg.test(`admin@xgqfrms.xyz`);
// true
// reg.test(`"admin@xgqfrms.xyz"`);
// false
flags
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags
vue & form validation
password & re-sure password
// rules
{
passWord: [
{
required: true,
message: "请输入密码",
trigger: "change",
},
{
min: 3,
max: 20,
message: "长度在 3 到 20 个字符",
trigger: "blur",
}
],
passWordSure: [
{
required: true,
message: "请输入密码",
trigger: "change",
},
{
min: 3,
max: 20,
pattern: `^${this.$data.form.passWord}$`,
// pattern: `${this.$data.form.passWordSure}`,
message: "两次输入的密码不一致",
trigger: "blur",
}
],
}
ChildNode.remove()
https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove